ConstructorBuilder.SetSymCustomAttribute(String, Byte[]) Método

Definición

Establece el atributo personalizado de este constructor asociado a la información simbólica.

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

Parámetros

name
String

Nombre del atributo personalizado.

data
Byte[]

Valor del atributo personalizado.

Excepciones

Tipo contenedor que se ha creado mediante CreateType().

o bien

El módulo no tiene un escritor de símbolos definido. Por ejemplo, el módulo no es un módulo de depuración.

Comentarios

En el ejemplo de código siguiente se muestra el uso de 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})

Se aplica a