Export (0) Print
Expand All

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 ()
Not applicable.

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.

NoteNote:

Starting with the , 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 . For more information, see The .NET Framework 3.5 Architecture.

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 = 
   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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft