ModuleBuilder.CreateGlobalFunctions メソッド
アセンブリ: mscorlib (mscorlib.dll 内)



ユーザーがこの動的モジュール内ですべてのグローバル関数を定義後に、このメソッドが呼び出される必要があります。この関数が呼び出されると、グローバル関数またはグローバル データを新たに定義できなくなります。

CreateGlobalFunctions を使用して、DefineGlobalMethod で実装されている MethodBuilder から静的なグローバル メソッドを作成する方法を次の例に示します。CreateGlobalFunctions は、DefineGlobalMethod を使用して 1 つ以上のグローバル メソッドを実装した後に呼び出す必要があります。
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()
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();
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.get_CurrentDomain(); myAssemblyName = new AssemblyName(); myAssemblyName.set_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();

- ReflectionPermission SecurityAction.Demand、ReflectionEmit

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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からModuleBuilder.CreateGlobalFunctions メソッドを検索する場合は、下記のリンクをクリックしてください。

- ModuleBuilder.CreateGlobalFunctions メソッドのページへのリンク