Compartir a través de


ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) Método

Definición

Define un campo de datos inicializado en la sección .sdata del archivo portable ejecutable (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

Parámetros

name
String

El nombre que se usa para hacer referencia a los datos. name no puede contener valores null insertados.

data
Byte[]

Objeto binario grande (BLOB) de datos.

attributes
FieldAttributes

Los atributos para este campo. De manera predeterminada, es Static.

Devoluciones

Campo para hacer referencia a los datos.

Excepciones

La longitud de name es cero.

o bien

El tamaño de data es menor o igual que cero o mayor o igual que 0x3f0000.

name o data es null.

Ejemplos

En el ejemplo siguiente se usa el DefineInitializedData método para definir un campo de datos inicializado en la .sdata sección del archivo ejecutable portátil (PE).

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

Comentarios

Static se incluye automáticamente en attributes.

Los datos definidos por este método no se crean hasta que se llama al CreateGlobalFunctions método .

Nota

A partir de .NET Framework 2.0 Service Pack 1, este miembro ya no requiere ReflectionPermission con la ReflectionPermissionFlag.ReflectionEmit marca . (Consulte Problemas de seguridad en la emisión de reflexión). Para usar esta funcionalidad, la aplicación debe tener como destino .NET Framework 3.5 o posterior.

Se aplica a