Condividi tramite


MethodBuilder.SetSymCustomAttribute(String, Byte[]) Metodo

Definizione

Imposta un attributo personalizzato simbolico usando un BLOB.

public:
 void SetSymCustomAttribute(System::String ^ name, cli::array <System::Byte> ^ data);
public void SetSymCustomAttribute(string name, byte[] data);
member this.SetSymCustomAttribute : string * byte[] -> unit
Public Sub SetSymCustomAttribute (name As String, data As Byte())

Parametri

name
String

Nome dell'attributo personalizzato simbolico.

data
Byte[]

BLOB di byte che rappresenta il valore dell'attributo personalizzato simbolico.

Eccezioni

Il tipo contenitore è stato creato in precedenza con CreateType().

-oppure-

Il modulo che contiene il metodo non è un modulo di debug.

-oppure-

Per il metodo corrente la proprietà IsGenericMethod è true, ma la proprietà IsGenericMethodDefinition è false.

Esempio

L'esempio di codice seguente illustra l'utilizzo contestuale del SetSymCustomAttribute metodo per impostare i valori di byte per il nome e la chiave di un attributo personalizzato associato a un metodo.


MethodBuilder myMethod = myDynamicType.DefineMethod("MyMethod",
                    MethodAttributes.Public,
                    typeof(int),
                    new Type[] { typeof(string) });

// A 128-bit key in hex form, represented as a byte array.
byte[] keyVal = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
          0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xFF, 0xFF };	

System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
byte[] symFullName = encoder.GetBytes("My Dynamic Method");

myMethod.SetSymCustomAttribute("SymID", keyVal);
myMethod.SetSymCustomAttribute("SymFullName", symFullName);
Dim myMethod As MethodBuilder = myDynamicType.DefineMethod("MyMethod", _
               MethodAttributes.Public, GetType(Integer), _
               New Type() {GetType(String)})

' A 128-bit key in hex form, represented as a byte array.
Dim keyVal As Byte() =  {&H0, &H0, &H0, &H0, &H0, &H0, &H0, &H0, _
             &H0, &H0, &H0, &H0, &H0, &H60, &HFF, &HFF}

Dim encoder As New System.Text.ASCIIEncoding()
Dim symFullName As Byte() = encoder.GetBytes("My Dynamic Method")

myMethod.SetSymCustomAttribute("SymID", keyVal)
myMethod.SetSymCustomAttribute("SymFullName", symFullName)

Commenti

A differenza dell'attributo personalizzato dei metadati, questo attributo personalizzato è associato a un writer di simboli.

Si applica a