ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Definuje inicializovaná datová pole v oddílu. sdata souboru přenositelného spustitelného souboru (PE).
public:
System::Reflection::Emit::FieldBuilder ^ DefineInitializedData(System::String ^ name, cli::array <System::Byte> ^ data, System::Reflection::FieldAttributes attributes);
public System.Reflection.Emit.FieldBuilder DefineInitializedData (string name, byte[] data, System.Reflection.FieldAttributes attributes);
member this.DefineInitializedData : string * byte[] * System.Reflection.FieldAttributes -> System.Reflection.Emit.FieldBuilder
Public Function DefineInitializedData (name As String, data As Byte(), attributes As FieldAttributes) As FieldBuilder
Parametry
- name
- String
Název, který se používá k odkazování na data. name
nelze obsahovat vložené hodnoty null.
- data
- Byte[]
Binární rozsáhlý objekt (BLOB) dat.
- attributes
- FieldAttributes
Atributy pole Výchozí formát je Static
.
Návraty
Pole, na které se mají odkazovat data
Výjimky
Délka name
je nula.
-nebo-
Velikost data
je menší než nebo rovna nule nebo větší než 0x3f0000.
name
nebo data
je null
.
CreateGlobalFunctions() byl dříve volán.
Příklady
Následující příklad používá DefineInitializedData metodu k definování inicializovaného datového pole v .sdata
části přenositelného spustitelného souboru (PE).
AppDomain^ currentDomain;
AssemblyName^ myAssemblyName;
// Get the current application domain for the current thread.
currentDomain = AppDomain::CurrentDomain;
myAssemblyName = gcnew AssemblyName;
myAssemblyName->Name = "TempAssembly";
// Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder =
currentDomain->DefineDynamicAssembly(
myAssemblyName, AssemblyBuilderAccess::Run );
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );
// Define the initialized data field in the .sdata section of the PE file.
array<Byte>^ temp0 = {01,00,01};
FieldBuilder^ myFieldBuilder =
myModuleBuilder->DefineInitializedData( "MyField", temp0,
(FieldAttributes)(FieldAttributes::Static | FieldAttributes::Public) );
myModuleBuilder->CreateGlobalFunctions();
AppDomain currentDomain;
AssemblyName myAssemblyName;
// Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain;
myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder =
currentDomain.DefineDynamicAssembly
(myAssemblyName, AssemblyBuilderAccess.Run);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");
// Define the initialized data field in the .sdata section of the PE file.
FieldBuilder myFieldBuilder =
myModuleBuilder.DefineInitializedData("MyField",new byte[]{01,00,01},
FieldAttributes.Static|FieldAttributes.Public);
myModuleBuilder.CreateGlobalFunctions();
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
' Get the current application domain for the current thread.
currentDomain = AppDomain.CurrentDomain
myAssemblyName = New AssemblyName()
myAssemblyName.Name = "TempAssembly"
' Define a dynamic assembly in the 'currentDomain'.
myAssemblyBuilder = _
currentDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")
' Define the initialized data field in the .sdata section of the PE file.
Dim myFieldBuilder As FieldBuilder = _
myModuleBuilder.DefineInitializedData("MyField", New Byte() {1, 0, 1}, _
FieldAttributes.Static Or FieldAttributes.Public)
myModuleBuilder.CreateGlobalFunctions()
Poznámky
Static je automaticky zahrnutý v attributes
.
Data definovaná pomocí této metody nejsou vytvořena, dokud CreateGlobalFunctions není volána metoda.
Poznámka
počínaje verzí .NET Framework 2,0 Service Pack 1 již tento člen nepotřebuje ReflectionPermission s ReflectionPermissionFlag.ReflectionEmit příznakem. (Viz problémy se zabezpečením při generování reflexe.) chcete-li použít tuto funkci, vaše aplikace by měla cílit na .NET Framework 3,5 nebo novější.