ComClassAttribute 类

定义

ComClassAttribute 特性指示编译器添加使类可以作为 COM 对象公开的元数据。

public ref class ComClassAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class ComClassAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)>]
type ComClassAttribute = class
    inherit Attribute
Public NotInheritable Class ComClassAttribute
Inherits Attribute
继承
ComClassAttribute
属性

示例

若要运行此示例,请创建新的 类库 应用程序,并将以下代码添加到类模块。

    <ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)>
    Public Class ComClass1
        ' Use the Region directive to define a section named COM Guids. 
#Region "COM GUIDs"
        ' These  GUIDs provide the COM identity for this class 
        ' and its COM interfaces. You can generate 
        ' these guids using guidgen.exe
        Public Const ClassId As String = "7666AC25-855F-4534-BC55-27BF09D49D46"
        Public Const InterfaceId As String = "54388137-8A76-491e-AA3A-853E23AC1217"
        Public Const EventsId As String = "EA329A13-16A0-478d-B41F-47583A761FF2"
#End Region

        Public Sub New()
            MyBase.New()
        End Sub

        Function AddNumbers(ByVal X As Integer, ByVal Y As Integer)
            AddNumbers = X + Y
        End Function
    End Class

注解

用于ComClassAttribute简化从 Visual Basic公开 COM 组件的过程。 COM 对象与.NET Framework程序集大不相同;无需ComClassAttribute执行许多步骤即可从Visual Basic生成 COM 对象。 对于标有 ComClassAttribute 的类,编译器会自动执行其中的许多步骤。

备注

此属性简化了 COM 对象的创建。 若要将类公开为 COM 对象,必须使用在“配置属性”对话框的“生成”部分中选择的“注册 COM 互操作”选项编译项目。

备注

虽然还可以公开使用 Visual Basic 创建的类作为 COM 对象,以便使用非托管代码,但它不是真正的 COM 对象。 有关详细信息,请参阅 .NET Framework 应用程序中的 COM 互操作性

构造函数

ComClassAttribute()

初始化 ComClassAttribute 类的新实例。

ComClassAttribute(String)

初始化 ComClassAttribute 类的新实例。

ComClassAttribute(String, String)

初始化 ComClassAttribute 类的新实例。

ComClassAttribute(String, String, String)

初始化 ComClassAttribute 类的新实例。

属性

ClassID

获取一个用于唯一标识类的类 ID。

EventID

获取一个用于唯一标识事件的事件 ID。

InterfaceID

获取一个用于唯一标识接口的接口 ID。

InterfaceShadows

指示 COM 接口名称是否隐藏类或基类的另一个成员。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

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

检索对象提供的类型信息接口的数量(0 或 1)。

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

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅