Bagikan melalui


MethodBuilder.SetSymCustomAttribute(String, Byte[]) Metode

Definisi

Atur atribut kustom simbolis menggunakan 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())

Parameter

name
String

Nama atribut kustom simbolis.

data
Byte[]

Blob byte yang mewakili nilai atribut kustom simbolis.

Pengecualian

Jenis yang berisi sebelumnya dibuat menggunakan CreateType().

-atau-

Modul yang berisi metode ini bukan modul debug.

-atau-

Untuk metode saat ini, IsGenericMethod properti adalah true, tetapi IsGenericMethodDefinition propertinya adalah false.

Contoh

Sampel kode di bawah ini menggambarkan penggunaan SetSymCustomAttribute kontekstual metode untuk mengatur nilai byte untuk nama dan kunci atribut kustom yang dilampirkan ke metode .

array<Type^>^ temp0 = { String::typeid };
MethodBuilder^ myMethod = myDynamicType->DefineMethod( "MyMethod",
                          MethodAttributes::Public,
                          int::typeid,
                          temp0 );

// A 128-bit key in hex form, represented as a Byte array.
array<Byte>^ keyVal = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xFF, 0xFF};

System::Text::ASCIIEncoding^ encoder = gcnew System::Text::ASCIIEncoding;
array<Byte>^ symFullName = encoder->GetBytes( "My Dynamic Method" );

myMethod->SetSymCustomAttribute( "SymID", keyVal );
myMethod->SetSymCustomAttribute( "SymFullName", symFullName );

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)

Keterangan

Tidak seperti atribut kustom metadata, atribut kustom ini dikaitkan dengan penulis simbol.

Berlaku untuk