次の方法で共有


MethodBuilder.SetSymCustomAttribute メソッド

BLOB を使用して、シンボリック カスタム属性を設定します。

Public Sub SetSymCustomAttribute( _
   ByVal name As String, _   ByVal data() As Byte _)
[C#]
public void SetSymCustomAttribute(stringname,byte[] data);
[C++]
public: void SetSymCustomAttribute(String* name,unsigned chardata __gc[]);
[JScript]
public function SetSymCustomAttribute(
   name : String,data : Byte[]);

パラメータ

  • name
    シンボリック カスタム属性の名前。
  • data
    シンボリック カスタム属性の値を表すバイト BLOB。

例外

例外の種類 条件
InvalidOperationException 外側の型が CreateType を使用して作成されています。

または

このメソッドを格納しているモジュールが、デバッグ モジュールではありません。

解説

メタデータ カスタム属性とは異なり、このカスタム属性はシンボル ライタに関連付けられます。

使用例

[Visual Basic, C#, C++] SetSymCustomAttribute メソッドを使用して、動的メソッドに結び付けられているカスタム属性の名前とキーにバイト値を設定する方法については、次のコード例を参照してください。

 
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)


[C#] 

    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);


[C++] 
Type* temp0 [] = {__typeof(String)};
MethodBuilder*  myMethod = myDynamicType->DefineMethod(
   S"MyMethod",
   MethodAttributes::Public,
   __typeof(int),
   temp0);

// 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(S"My Dynamic Method");

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

MethodBuilder クラス | MethodBuilder メンバ | System.Reflection.Emit 名前空間