MethodBuilder.SetSymCustomAttribute Method

Set a symbolic custom attribute using a blob.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public void SetSymCustomAttribute (
	string name,
	byte[] data
)
public void SetSymCustomAttribute (
	String name, 
	byte[] data
)
public function SetSymCustomAttribute (
	name : String, 
	data : byte[]
)

Parameters

name

The name of the symbolic custom attribute.

data

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

Exception typeCondition

InvalidOperationException

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.

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

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.


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


MethodBuilder myMethod = myDynamicType.DefineMethod("MyMethod", 
    MethodAttributes.Public, int.class.ToType(), 
    new Type[] { String.class.ToType() });

// A 128-bit key in hex form, represented as a byte array.
ubyte keyVal[] =  { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x60, 0xFF, 0xFF };
System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
ubyte symFullName[] = encoder.GetBytes("My Dynamic Method");
myMethod.SetSymCustomAttribute("SymID", keyVal);
myMethod.SetSymCustomAttribute("SymFullName", symFullName);

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: