DispIdAttribute Class
Specifies the COM dispatch identifier (DISPID) of a method, field, or property.
For a list of all members of this type, see DispIdAttribute Members.
System.Object
System.Attribute
System.Runtime.InteropServices.DispIdAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.Method Or _ AttributeTargets.Property Or AttributeTargets.Field Or _ AttributeTargets.Event)> NotInheritable Public Class DispIdAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event)] public sealed class DispIdAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::Method | AttributeTargets::Property | AttributeTargets::Field | AttributeTargets::Event)] public __gc __sealed class DispIdAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event) class DispIdAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
You can apply this attribute to methods, fields, or properties.
This attribute contains the DISPID for the method, field, or property it describes. Unique DISPIDs are typically assigned by the common language runtime, but you can use this attribute to assign a specific DISPID to a method. When importing a type library, this attribute is applied to all methods with assigned DISPIDs. This ensures that any managed implementation of the same method retains the same DISPID if exposed to COM.
Example
[Visual Basic, C#, C++] The following example demonstrates how explicit DISPIDs can be assigned to members of a class.
[Visual Basic] 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 [C#] using System.Runtime.InteropServices; public class MyClass { public MyClass() {} [DispId(8)] public void MyMethod() {} public int MyOtherMethod() { return 0; } [DispId(9)] public bool MyField; } [C++] using namespace System::Runtime::InteropServices; public __gc class MyClass { public: MyClass() {} public: [DispId(8)] void MyMethod() {} public: int MyOtherMethod() { return 0; } public: [DispId(9)] bool MyField; };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Runtime.InteropServices
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)
See Also
DispIdAttribute Members | System.Runtime.InteropServices Namespace