ModuleBuilder.DefineInitializedData-Methode
Definiert ein initialisiertes Datenfeld im .sdata-Abschnitt der übertragbaren ausführbaren Datei (Portable Executable, PE).
Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Function DefineInitializedData ( _
name As String, _
data As Byte(), _
attributes As FieldAttributes _
) As FieldBuilder
'Usage
Dim instance As ModuleBuilder
Dim name As String
Dim data As Byte()
Dim attributes As FieldAttributes
Dim returnValue As FieldBuilder
returnValue = instance.DefineInitializedData(name, data, attributes)
public FieldBuilder DefineInitializedData (
string name,
byte[] data,
FieldAttributes attributes
)
public:
FieldBuilder^ DefineInitializedData (
String^ name,
array<unsigned char>^ data,
FieldAttributes attributes
)
public FieldBuilder DefineInitializedData (
String name,
byte[] data,
FieldAttributes attributes
)
public function DefineInitializedData (
name : String,
data : byte[],
attributes : FieldAttributes
) : FieldBuilder
Parameter
- name
Der Name, der für den Verweis auf die Daten verwendet wird. name darf keine eingebetteten NULL-Werte enthalten
- data
Das Daten-BLOB.
- attributes
Die Attribute für das Feld. Der Standardwert ist Static.
Rückgabewert
Ein Feld zum Verweisen auf die Daten.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Die Länge von name ist 0 (null). - oder - Die Größe von data ist kleiner oder gleich 0 bzw. größer oder gleich 0x3f0000. |
|
name oder data ist NULL (Nothing in Visual Basic). |
|
CreateGlobalFunctions wurde bereits zuvor aufgerufen. |
Hinweise
Static wird automatisch in attributes eingefügt.
Die von dieser Methode definierten Daten werden erst nach dem Aufruf der CreateGlobalFunctions-Methode erstellt.
Beispiel
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()
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();
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.get_CurrentDomain();
myAssemblyName = new AssemblyName();
myAssemblyName.set_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 ubyte[] { 1, 0, 1 },
FieldAttributes.Static | FieldAttributes.Public);
myModuleBuilder.CreateGlobalFunctions();
.NET Framework-Sicherheit
- ReflectionPermission SecurityAction.Demand, ReflectionEmit
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ModuleBuilder-Klasse
ModuleBuilder-Member
System.Reflection.Emit-Namespace