英語で読む

次の方法で共有


ModuleBuilder.DefineInitializedData(String, Byte[], FieldAttributes) メソッド

定義

移植可能な実行可能 (PE) ファイルの .sdata セクションに、初期化済みデータ フィールドを定義します。

C#
public System.Reflection.Emit.FieldBuilder DefineInitializedData(string name, byte[] data, System.Reflection.FieldAttributes attributes);

パラメーター

name
String

データを参照するために使用する名前。 name に埋め込み null 値を含めることはできません。

data
Byte[]

データのバイナリ ラージ オブジェクト (BLOB)。

attributes
FieldAttributes

フィールドの属性。 既定値は、Static です。

戻り値

データを参照するフィールド。

例外

name の長さが 0 です。

- または -

data のサイズが 0 以下か、0x3f0000 以上です。

name または datanull です。

CreateGlobalFunctions() は以前に呼び出されています。

次の例では、 メソッドを DefineInitializedData 使用して、ポータブル実行可能ファイル (PE) ファイルの セクションで .sdata 初期化されたデータ フィールドを定義します。

C#
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();

注釈

Static は に自動的に attributes含まれます。

このメソッドで定義されたデータは、 メソッドが CreateGlobalFunctions 呼び出されるまで作成されません。

注意

.NET Framework 2.0 Service Pack 1 以降では、このメンバーは フラグをReflectionPermissionFlag.ReflectionEmit使用する必要ReflectionPermissionがなくなりました。 (リフレクション出力のセキュリティの問題に関するページを参照してください)。この機能を使用するには、アプリケーションで .NET Framework 3.5 以降をターゲットにする必要があります。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1