MethodBuilder.SetSymCustomAttribute(String, Byte[]) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
用 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[]
代表符號自訂屬性值的位元組塊。
例外狀況
包含型態先前是使用 CreateType()。
-或-
包含此方法的模組並非除錯模組。
-或-
對於目前的方法,性質 IsGenericMethod 為 true,但性質 IsGenericMethodDefinition 為 false。
範例
以下範例程式碼說明了該方法在情境上的使用 SetSymCustomAttribute ,用於設定附加於方法的自訂屬性名稱與鍵的位元組值。
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)
備註
與元資料自訂屬性不同,此自訂屬性與符號撰寫器相關聯。