Szerkesztés

Megosztás a következőn keresztül:


MethodBuilder.SetSymCustomAttribute(String, Byte[]) Method

Definition

Set a symbolic custom attribute using a 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())

Parameters

name
String

The name of the symbolic custom attribute.

data
Byte[]

The byte blob that represents the value of the symbolic custom attribute.

Exceptions

The containing type was previously created using CreateType().

-or-

The module that contains this method is not a debug module.

-or-

For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

Examples

The code sample below illustrates the contextual usage of the SetSymCustomAttribute method to set the byte values for the name and key of a custom attribute attached to a method.

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)

Remarks

Unlike the metadata custom attribute, this custom attribute is associated with a symbol writer.

Applies to