DispIdAttribute Classe

Definizione

Specifica l'identificatore di invio (DISPID) COM di un metodo, un campo o una proprietà.

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
Ereditarietà
DispIdAttribute
Attributi

Esempio

Nell'esempio seguente viene illustrato come è possibile assegnare i DISPID espliciti ai membri di una classe.

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

Commenti

È possibile applicare questo attributo a metodi, campi o proprietà.

Questo attributo contiene il DISPID per il metodo, il campo o la proprietà che descrive. I DISPID univoci vengono in genere assegnati dal common language runtime, ma è possibile usare questo attributo per assegnare un DISPID specifico a un metodo. Quando si importa una libreria di tipi, questo attributo viene applicato a tutti i metodi con DISPID assegnati. Ciò garantisce che qualsiasi implementazione gestita dello stesso metodo mantenga lo stesso DISPID se esposto a COM.

Per un elenco di valori DISPID comunemente usati, vedere Costanti DISPID .

Costruttori

DispIdAttribute(Int32)

Inizializza una nuova istanza della classe DispIdAttribute con il DISPID specificato.

Proprietà

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)
Value

Ottiene il DISPID del membro.

Metodi

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a