ConstructorBuilder.SetSymCustomAttribute(String, Byte[]) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Définit l’attribut personnalisé de ce constructeur associé aux informations symboliques.
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())
Paramètres
- name
- String
Nom de l’attribut personnalisé.
- data
- Byte[]
Valeur de l'attribut personnalisé.
Exceptions
Le type conteneur a été créé à l’aide de CreateType().
- ou -
Le module n’a pas de writer de symbole défini. Par exemple, le module n’est pas un module de débogage.
Remarques
L’exemple de code suivant illustre l’utilisation 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})