MethodBuilder.SetSymCustomAttribute(String, Byte[]) 方法

定義

使用 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())

參數

name
String

符號自訂屬性的名稱。

data
Byte[]

位元組 Blob,代表符號自訂屬性的值。

例外狀況

先前已使用 CreateType() 建立包含類型。

-或-

包含這個方法的模組不是偵錯模組。

-或-

針對於目前的方法,IsGenericMethod 屬性為 true,但 IsGenericMethodDefinition 屬性為 false

範例

下列程式代碼範例說明方法的內容使用 SetSymCustomAttribute 方式,以設定附加至方法之自定義屬性名稱和索引鍵的位元組值。

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)

備註

不同於元數據自定義屬性,這個自定義屬性與符號寫入器相關聯。

適用於