ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Inicializált adatmezőt határoz meg a hordozható végrehajtható (PE) fájl .sdata szakaszában.
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
Paraméterek
- name
- String
Az adatokra való hivatkozáshoz használt név.
name nem tartalmazhat beágyazott null értékeket.
- data
- Byte[]
Az adatok bináris nagy objektuma (BLOB).
- attributes
- FieldAttributes
A mező attribútumai. Az alapértelmezett érték a Static.
Válaszok
Az adatokra hivatkozó mező.
Kivételek
A hossz name nulla.
-vagy-
A méret data kisebb, mint nulla vagy nagyobb, mint 0x3f0000.
name vagy data az null.
CreateGlobalFunctions() korábban már meghívták.
Példák
Az alábbi példa egy inicializált adatmező meghatározására használható a DefineInitializedData hordozható végrehajtható fájl (PE) szakaszában .sdata .
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()
Megjegyzések
Static automatikusan bekerül a fájlba attributes.
A metódus által definiált adatok csak a CreateGlobalFunctions metódus meghívása után jönnek létre.