Bewerken

Share via


ConstructorBuilder.SetSymCustomAttribute(String, Byte[]) Method

Definition

Sets this constructor's custom attribute associated with symbolic information.

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 custom attribute.

data
Byte[]

The value of the custom attribute.

Exceptions

The containing type has been created using CreateType().

-or-

The module does not have a symbol writer defined. For example, the module is not a debug module.

Remarks

The following code sample illustrates the use of SetSymCustomAttributes.

MethodBuilder^ myMethodBuilder = nullptr;
AppDomain^ myCurrentDomain = AppDomain::CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName^ myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain->DefineDynamicAssembly(
   myAssemblyName, AssemblyBuilderAccess::Run );
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule", true );
FieldInfo^ myFieldInfo =
   myModuleBuilder->DefineUninitializedData( "myField", 2, FieldAttributes::Public );
// Create a type in the module.
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType( "TempClass", TypeAttributes::Public );
FieldBuilder^ myGreetingField = myTypeBuilder->DefineField( "Greeting",
   String::typeid, FieldAttributes::Public );
array<Type^>^ myConstructorArgs = {String::typeid};
// Define a constructor of the dynamic class.
ConstructorBuilder^ myConstructor = myTypeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, myConstructorArgs );
// Display the name of the constructor.
Console::WriteLine( "The constructor name is  : {0}", myConstructor->Name );
array<Byte>^ temp0 = {01,00,00};
myConstructor->SetSymCustomAttribute( "MySimAttribute", temp0 );
MethodBuilder myMethodBuilder = null;
AppDomain myCurrentDomain = AppDomain.CurrentDomain;
// Create assembly in current CurrentDomain.
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly
         (myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule",true);
FieldInfo myFieldInfo =
   myModuleBuilder.DefineUninitializedData("myField", 2, FieldAttributes.Public);
// Create a type in the module.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("TempClass",TypeAttributes.Public);
FieldBuilder myGreetingField = myTypeBuilder.DefineField("Greeting",
                                    typeof(String), FieldAttributes.Public);
Type[] myConstructorArgs = { typeof(String) };
// Define a constructor of the dynamic class.
ConstructorBuilder myConstructor = myTypeBuilder.DefineConstructor(
MethodAttributes.Public, CallingConventions.Standard, myConstructorArgs);
// Display the name of the constructor.
Console.WriteLine("The constructor name is  : "+ myConstructor.Name);
myConstructor.SetSymCustomAttribute("MySimAttribute", new byte[]{01,00,00});
Dim myMethodBuilder As MethodBuilder = Nothing
Dim myCurrentDomain As AppDomain = AppDomain.CurrentDomain
' Create assembly in current CurrentDomain.
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Create a dynamic assembly.
myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly(myAssemblyName, _
           AssemblyBuilderAccess.Run)
' Create a dynamic module in the assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule", True)
Dim myFieldInfo As FieldInfo = myModuleBuilder.DefineUninitializedData("myField", 2, _
           FieldAttributes.Public)
' Create a type in the module.
Dim myTypeBuilder As TypeBuilder = myModuleBuilder.DefineType("TempClass", TypeAttributes.Public)
Dim myGreetingField As FieldBuilder = myTypeBuilder.DefineField("Greeting", GetType(String), _
           FieldAttributes.Public)
Dim myConstructorArgs() As Type = { GetType(String) }
' Define a constructor of the dynamic class.
Dim myConstructor As ConstructorBuilder = _
          myTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, _
           myConstructorArgs)
' Display the name of the constructor.
Console.WriteLine("The constructor name is  : " + myConstructor.Name)
myConstructor.SetSymCustomAttribute("MySimAttribute", New Byte() {01, 00,00})

Applies to