ComEventInterfaceAttribute 类



此 API 现已过时。

标识源接口和实现事件接口方法的类,事件接口在从 COM 类型库中导入组件类时生成。Identifies the source interface and the class that implements the methods of the event interface that is generated when a coclass is imported from a COM type library.

public ref class ComEventInterfaceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
[System.Obsolete("ComEventInterfaceAttribute may be unavailable in future releases.")]
public sealed class ComEventInterfaceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
public sealed class ComEventInterfaceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
public sealed class ComEventInterfaceAttribute : Attribute
type ComEventInterfaceAttribute = class
    inherit Attribute
Public NotInheritable Class ComEventInterfaceAttribute
Inherits Attribute


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

从类型库导入源接口时,它实现的任何方法都将作为事件添加到生成的事件接口。When a source interface is imported from a type library, any methods it implements are added as events to a generated event interface. Tlbimp.exe 将 ComEventInterfaceAttribute 应用于事件接口,以标识实现事件接口的方法并实现原始源接口的托管类。Tlbimp.exe applies ComEventInterfaceAttribute to the event interface to identify the managed class that implements the methods of the event interface and implements the original source interface. 公共语言运行时在运行时使用此属性来执行以下任务:The common language runtime uses this attribute at run time to perform the following tasks:

  • 将接口公开的事件与事件提供程序类中的实现相关联。Associate events exposed by the interface to their implementation in the event provider class.

  • 将事件链接到原始 COM 源接口。Link the events to the original COM source interface.

很少应用此特性。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 event interface for each original source interface. 有关 Tlbimp.exe 如何导入事件的详细说明,请参阅导入成员转换For a detailed description about how Tlbimp.exe imports events, see Imported Member Conversion. 有关如何向 .NET 客户端公开 COM 事件的说明,请参阅如何:处理由 Com 源引发的事件For instruction about how to expose a COM event to a .NET client, see How to: Handle Events Raised by a COM Source.


ComEventInterfaceAttribute(Type, Type)

用源接口和事件提供程序类初始化 ComEventInterfaceAttribute 类的新实例。Initializes a new instance of the ComEventInterfaceAttribute class with the source interface and event provider class.



获取实现事件接口方法的类。Gets the class that implements the methods of the event interface.


从类型库获取原始源接口。Gets the original source interface from the type library.


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

(继承自 Attribute)



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

(继承自 Attribute)

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

(继承自 Attribute)

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

(继承自 Object)

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

(继承自 Attribute)

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

(继承自 Attribute)

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

(继承自 Object)

返回表示当前对象的字符串。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)

检索对象提供的类型信息接口的数量(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)