CreateGlobalFunctions Method

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

Exception Condition

This method was called previously.

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


Starting with the .NET Framework 2.0 Service Pack 1, this member no longer requires ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the .NET Framework 3.5 or later.

The following sample illustrates the use of CreateGlobalFunctions to create a static global method from a MethodBuilder implemented with DefineGlobalMethod.

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 = 
               (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
myILGenerator = myMethodBuilder.GetILGenerator();
myILGenerator.EmitWriteLine("Hello World from global method.");
// Fix up the 'TempModule' module .

.NET Framework
Available since 1.1
Available since 2.0
Return to top
© 2015 Microsoft