ModuleBuilder.CreateGlobalFunctions メソッド

定義

この動的モジュールのグローバル関数定義とグローバル データ定義を完了します。

public:
 void CreateGlobalFunctions();
public void CreateGlobalFunctions ();
member this.CreateGlobalFunctions : unit -> unit
Public Sub CreateGlobalFunctions ()

例外

このメソッドは、既に呼び出されています。

次の例では、 を使用して を使用CreateGlobalFunctionsして 実装された DefineGlobalMethodから静的グローバル メソッドを作成する方法をMethodBuilder示します。

AppDomain^ currentDomain;
AssemblyName^ myAssemblyName;
MethodBuilder^ myMethodBuilder = nullptr;
ILGenerator^ myILGenerator;

// 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::RunAndSave );

// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder->DefineDynamicModule( "TempModule" );

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder->DefineGlobalMethod(
   "MyMethod1", (MethodAttributes)(MethodAttributes::Static | MethodAttributes::Public),
   nullptr, nullptr );
myILGenerator = myMethodBuilder->GetILGenerator();
myILGenerator->EmitWriteLine( "Hello World from global method." );
myILGenerator->Emit( OpCodes::Ret );

// Fix up the 'TempModule' module .
myModuleBuilder->CreateGlobalFunctions();
AppDomain currentDomain;
AssemblyName myAssemblyName;
MethodBuilder myMethodBuilder=null;
ILGenerator myILGenerator;

// 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.RunAndSave);
// Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule");

// Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod
     ("MyMethod1",MethodAttributes.Static|MethodAttributes.Public,
           null,null);
myILGenerator = myMethodBuilder.GetILGenerator();
myILGenerator.EmitWriteLine("Hello World from global method.");
myILGenerator.Emit(OpCodes.Ret);
// Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions();
Dim currentDomain As AppDomain
Dim myAssemblyName As AssemblyName
Dim myMethodBuilder As MethodBuilder = Nothing
Dim myILGenerator As ILGenerator

' 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.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly.
myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")

' Define a global method in the 'TempModule' module.
myMethodBuilder = myModuleBuilder.DefineGlobalMethod("MyMethod1", MethodAttributes.Static _
                                          Or MethodAttributes.Public, Nothing, Nothing)
myILGenerator = myMethodBuilder.GetILGenerator()
myILGenerator.EmitWriteLine("Hello World from global method.")
myILGenerator.Emit(OpCodes.Ret)
' Fix up the 'TempModule' module .
myModuleBuilder.CreateGlobalFunctions()

注釈

このメソッドは、ユーザーがこの動的モジュール内のすべてのグローバル関数の定義を行うときに呼び出す必要があります。 この関数を呼び出した後は、新しいグローバル関数や新しいグローバル データは使用できません。

Note

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

適用対象