ModuleBuilder.CreateGlobalFunctions Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Completes the global function definitions and global data definitions for this dynamic module.
public:
void CreateGlobalFunctions();
public void CreateGlobalFunctions ();
member this.CreateGlobalFunctions : unit -> unit
Public Sub CreateGlobalFunctions ()
This method was called previously.
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 = 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()
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.
Anteckning
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.
Produkt | Versioner |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
Feedback om .NET
.NET är ett öppen källkod projekt. Välj en länk för att ge feedback: