ModuleBuilder.CreateGlobalFunctions Method

Completes the global function definitions and global data definitions for this dynamic module.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

public void CreateGlobalFunctions ()
public void CreateGlobalFunctions ()
public function CreateGlobalFunctions ()

Exception typeCondition

InvalidOperationException

This method was called previously.

This method should be called when the user is done with defining all of the global functions within this dynamic module. After calling this function, no more new global functions or new global data are allowed.

The following sample illustrates the use of CreateGlobalFunctions to create a static global method from a MethodBuilder implemented with DefineGlobalMethod. Note that CreateGlobalFunctions must be called after DefineGlobalMethod has been used to implement at least one global method.

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

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: