Export (0) Print
Expand All

ModuleBuilder.DefineInitializedData Method

Defines an initialized data field in the .sdata section of the portable executable (PE) file.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public FieldBuilder DefineInitializedData (
	string name,
	byte[] data,
	FieldAttributes attributes
)
public FieldBuilder DefineInitializedData (
	String name, 
	byte[] data, 
	FieldAttributes attributes
)
public function DefineInitializedData (
	name : String, 
	data : byte[], 
	attributes : FieldAttributes
) : FieldBuilder

Parameters

name

The name used to refer to the data. name cannot contain embedded nulls.

data

The blob of data.

attributes

The attributes for the field. The default is Static.

Return Value

A field to reference the data.

Exception typeCondition

ArgumentException

The length of name is zero.

-or-

The size of data is less than or equal to zero or greater than or equal to 0x3f0000.

ArgumentNullException

name or data is a null reference (Nothing in Visual Basic).

InvalidOperationException

CreateGlobalFunctions has been previously called.

Static is automatically included in attributes.

The data defined by this method is not created until the CreateGlobalFunctions method is called.

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

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft