ComSourceInterfacesAttribute 类

为属性化类标识公开为 COM 事件源的一组接口。

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Class, Inherited:=True)> _
Public NotInheritable Class ComSourceInterfacesAttribute
    Inherits Attribute
用法
Dim instance As ComSourceInterfacesAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Class, Inherited=true)] 
public sealed class ComSourceInterfacesAttribute : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Class, Inherited=true)] 
public ref class ComSourceInterfacesAttribute sealed : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, Inherited=true) */ 
public final class ComSourceInterfacesAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Class, Inherited=true) 
public final class ComSourceInterfacesAttribute extends Attribute

备注

可将该属性应用于类。

可将此属性应用于托管类,以标识该类作为 COM 连接点所公开的事件接口。事件接口包含映射到类的事件成员的方法。类事件的名称和接口方法的名称必须相同。对于一个类,此属性最多可容纳 4 个源接口,方法是将源接口的类型传递给适当的构造函数,这些构造函数带 1 至 4 个类型参数。对于要公开 4 个以上的源接口的类,可使用构造函数的字符串版本。有关向 COM 客户端公开 .NET 事件的其他信息,请参见 如何:引发 COM 接收器所处理的事件

示例

下面的示例演示了如何应用 ComSourceInterfacesAttribute,通过传递命名空间和事件接收器接口,将事件接收器接口连接到一个类。

Imports System.Runtime.InteropServices

<ComSourceInterfacesAttribute("ButtonEventsLib.ButtonEvents, ButtonEventsLib")> _
public Class Baz
    'Insert code here.
End Class
using System.Runtime.InteropServices;

[ComSourceInterfacesAttribute("ButtonEventsLib.ButtonEvents, ButtonEventsLib")]
public class Baz 
{
   //Insert code here.
}
using namespace System::Runtime::InteropServices;

[ComSourceInterfacesAttribute("ButtonEventsLib.ButtonEvents, ButtonEventsLib")]
public ref class Baz{};
import System.Runtime.InteropServices.*;

/** @attribute ComSourceInterfacesAttribute("ButtonEventsLib.ButtonEvents," 
    + " ButtonEventsLib")
 */
public class Baz
{
    //Insert code here.
} //Baz
import System.Runtime.InteropServices;

ComSourceInterfacesAttribute("ButtonEventsLib.ButtonEvents, ButtonEventsLib") public class Baz 
{
   //Insert code here.
}

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.ComSourceInterfacesAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

ComSourceInterfacesAttribute 成员
System.Runtime.InteropServices 命名空间