CoClassAttribute 类

定义

指定从类型库导入的组件类的类标识符。Specifies the class identifier of a coclass imported from a type library.

public ref class CoClassAttribute sealed : Attribute
public sealed class CoClassAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
public sealed class CoClassAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class CoClassAttribute : Attribute
type CoClassAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)>]
type CoClassAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CoClassAttribute = class
    inherit Attribute
Public NotInheritable Class CoClassAttribute
Inherits Attribute
继承
CoClassAttribute
属性

注解

可以将此特性应用于 coclass 接口,不过 Tlbimp.exe (类型库导) 入 程序在导入类型库时通常会应用它。You can apply this attribute to coclass interfaces, although the Tlbimp.exe (Type Library Importer) typically applies it for you when it imports a type library.

Tlbimp.exe 导入组件类时,它将生成一个托管类和一个用于表示组件类的接口。When Tlbimp.exe imports a coclass, it produces a managed class and an interface to represent the coclass. Coclass 接口的接口标识符 (IID) 为原始 coclass 的默认接口。The coclass interface has the same interface identifier (IID) as the default interface of the original coclass. 导入的 coclass 接口还会保留 coclass 的名称。The imported coclass interface also retains the name of the coclass. Tlbimp.exe 将原始 coclass 名称与 "class" 一起追加,以标识导入的类。Tlbimp.exe appends the original coclass name with "class" to identify the imported class.

很少应用此特性。You rarely apply this attribute. 但是,如果你计划编写源代码来生成可充分模拟 Tlbimp.exe 生成的元数据的元数据,则应为每个 coclass 创建组件类接口。However, if you plan to write source code that produces metadata that closely simulates metadata produced by Tlbimp.exe, you should create a coclass interface for each coclass. 使用原始 coclass 的名称命名 coclass 接口,并从默认接口派生。Use the name of the original coclass to name the coclass interface and derive it from the default interface. 除了之外 CoClassAttribute ,还必须将 System.Runtime.InteropServices.ComImportAttributeSystem.Runtime.InteropServices.GuidAttribute 特性应用到 coclass 接口。In addition to the CoClassAttribute, you must also apply the System.Runtime.InteropServices.ComImportAttribute and System.Runtime.InteropServices.GuidAttribute attributes to the coclass interface. 有关 Tlbimp.exe 如何从类型库导入接口和组件类的其他信息,请参阅 导入的类型转换For additional information about how Tlbimp.exe imports interfaces and coclasses from a type library, see Imported Type Conversion.

构造函数

CoClassAttribute(Type)

用原始 coclass 的类标识符初始化 CoClassAttribute 的新实例。Initializes new instance of the CoClassAttribute with the class identifier of the original coclass.

属性

CoClass

获取原始 coclass 的类标识符。Gets the class identifier of the original coclass.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅