CoClassAttribute CoClassAttribute CoClassAttribute CoClassAttribute Class

定义

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

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

注解

但可以用于 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)。The coclass interface has the same interface identifier (IID) as the default interface of the original coclass. 导入的组件类接口还保留组件类的名称。The imported coclass interface also retains the name of the coclass. Tlbimp.exe 将追加"类",以标识导入的类具有的原始组件类名称。Tlbimp.exe appends the original coclass name with "class" to identify the imported class.

很少会应用此属性。You rarely apply this attribute. 但是,如果你打算编写生成密切模拟由 Tlbimp.exe 生成的元数据的元数据的源代码,您应创建每个组件类的组件类接口。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. 使用原始组件类的名称进行命名的组件类接口和派生默认接口。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到组件类接口属性。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) CoClassAttribute(Type) CoClassAttribute(Type) CoClassAttribute(Type)

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

属性

CoClass CoClass CoClass CoClass

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

TypeId TypeId TypeId TypeId

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

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

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

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

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

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

显式界面实现

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

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

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

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

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(Inherited from Attribute)

适用于

另请参阅