Bagikan melalui


ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) Metode

Definisi

Menentukan bidang data yang diinisialisasi di bagian .sdata dari file portable executable (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

Parameter

name
String

Nama yang digunakan untuk merujuk ke data. name tidak boleh berisi null yang disematkan.

data
Byte[]

Objek besar biner (BLOB) data.

attributes
FieldAttributes

Atribut untuk bidang . Default adalah Static.

Mengembalikan

Bidang untuk mereferensikan data.

Pengecualian

Panjangnya name adalah nol.

-atau-

Ukuran data kurang dari atau sama dengan nol atau lebih besar dari atau sama dengan 0x3f0000.

name atau data adalah null.

Contoh

Contoh berikut menggunakan DefineInitializedData metode untuk menentukan bidang data yang diinisialisasi di .sdata bagian file portable executable (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()

Keterangan

Static secara otomatis disertakan dalam attributes.

Data yang ditentukan oleh metode ini tidak dibuat sampai CreateGlobalFunctions metode dipanggil.

Catatan

Dimulai dengan .NET Framework 2.0 Paket Layanan 1, anggota ini tidak lagi memerlukan ReflectionPermission bendera ReflectionPermissionFlag.ReflectionEmit . (Lihat Masalah Keamanan dalam Pancaran Pantulan.) Untuk menggunakan fungsionalitas ini, aplikasi Anda harus menargetkan .NET Framework 3.5 atau yang lebih baru.

Berlaku untuk