DispIdAttribute 类

定义

指定方法、字段或属性的 COM 调度标识符 (DISPID)。

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

示例

以下示例演示了如何将显式 DISPID 分配给类的成员。

using namespace System::Runtime::InteropServices;
public ref class MyClass
{
public:
   MyClass(){}


   [DispId(8)]
   void MyMethod(){}

   int MyOtherMethod()
   {
      return 0;
   }


   [DispId(9)]
   bool MyField;
};
using System.Runtime.InteropServices;

public class MyClass
{
   public MyClass() {}

   [DispId(8)]
   public void MyMethod() {}

   public int MyOtherMethod() {
      return 0;
   }

   [DispId(9)]
   public bool MyField;
}
Imports System.Runtime.InteropServices

Class SampleClass
    
    Public Sub New()
        'Insert code here.
    End Sub
    
    <DispIdAttribute(8)> _ 
    Public Sub MyMethod()
        'Insert code here.
    End Sub    
    
    Public Function MyOtherMethod() As Integer
        'Insert code here.
        Return 0
    End Function
    
    <DispId(9)> _
    Public MyField As Boolean
End Class

注解

可以将此属性应用于方法、字段或属性。

此特性包含适用于它所述的方法、字段或属性的 DISPID。 唯一 DISPID 通常由公共语言运行时分配,但你可以使用此属性将特定的 DISPID 分配给方法。 导入类型库时,此属性将应用于具有分配的 DISPID 的所有方法。 这可确保同一方法的任何托管实现在向 COM 公开时保留相同的 DISPID。

有关常用 DISPID 值的列表,请参阅 DISPID 常量。

构造函数

DispIdAttribute(Int32)

用指定的 DISPID 初始化 DispIdAttribute 类的新实例。

属性

TypeId

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

(继承自 Attribute)
Value

获取成员的 DISPID。

方法

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)

适用于