ModuleBuilder.DefineGlobalMethod Metod

Definition

Definierar en global metod.

Överlagringar

Name Description
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])

Definierar en global metod med angivet namn, attribut, anropande konvention, returtyp och parametertyper.

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

Definierar en global metod med angivet namn, attribut, anropskonvention, returtyp, anpassade modifierare för returtyp, parametertyper och anpassade modifierare för parametertyperna.

DefineGlobalMethod(String, MethodAttributes, Type, Type[])

Definierar en global metod med angivet namn, attribut, returtyp och parametertyper.

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[])

Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs

Definierar en global metod med angivet namn, attribut, anropande konvention, returtyp och parametertyper.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type()) As MethodBuilder

Parametrar

name
String

Namnet på metoden. name kan inte innehålla inbäddade null-värden.

attributes
MethodAttributes

Metodens attribut. attributes måste innehålla Static.

callingConvention
CallingConventions

Anropskonventionen för metoden.

returnType
Type

Metodens returtyp.

parameterTypes
Type[]

Typerna av metodens parametrar.

Returer

Den definierade globala metoden.

Undantag

Metoden är inte statisk. Det innebär attributes att inte innehåller Static.

-eller-

Ett element i matrisen Type är null.

name är null.

Exempel

Följande kodexempel illustrerar användningen av DefineGlobalMethod för att skapa en typoberoende metod som är kopplad till den aktuella ModuleBuilder. När du har skapat den globala metoden CreateGlobalFunctions måste anropas för att slutföra den.

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

Kommentarer

Du kan inte använda den globala metod som den här metoden definierar förrän du anropar CreateGlobalFunctions.

Gäller för

DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs

Definierar en global metod med angivet namn, attribut, anropskonvention, returtyp, anpassade modifierare för returtyp, parametertyper och anpassade modifierare för parametertyperna.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ requiredReturnTypeCustomModifiers, cli::array <Type ^> ^ optionalReturnTypeCustomModifiers, cli::array <Type ^> ^ parameterTypes, cli::array <cli::array <Type ^> ^> ^ requiredParameterTypeCustomModifiers, cli::array <cli::array <Type ^> ^> ^ optionalParameterTypeCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? requiredReturnTypeCustomModifiers, Type[]? optionalReturnTypeCustomModifiers, Type[]? parameterTypes, Type[][]? requiredParameterTypeCustomModifiers, Type[][]? optionalParameterTypeCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type[] * Type[] * Type[][] * Type[][] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, requiredReturnTypeCustomModifiers As Type(), optionalReturnTypeCustomModifiers As Type(), parameterTypes As Type(), requiredParameterTypeCustomModifiers As Type()(), optionalParameterTypeCustomModifiers As Type()()) As MethodBuilder

Parametrar

name
String

Namnet på metoden. name kan inte innehålla inbäddade null-tecken.

attributes
MethodAttributes

Metodens attribut. attributes måste innehålla Static.

callingConvention
CallingConventions

Anropskonventionen för metoden.

returnType
Type

Metodens returtyp.

requiredReturnTypeCustomModifiers
Type[]

En matris med typer som representerar nödvändiga anpassade modifierare för returtypen, till exempel IsConst eller IsBoxed. Om returtypen inte har några nödvändiga anpassade modifierare anger du null.

optionalReturnTypeCustomModifiers
Type[]

En matris med typer som representerar valfria anpassade modifierare för returtypen, till exempel IsConst eller IsBoxed. Om returtypen inte har några valfria anpassade modifierare anger du null.

parameterTypes
Type[]

Typerna av metodens parametrar.

requiredParameterTypeCustomModifiers
Type[][]

En matris med matriser av typer. Varje typmatris representerar nödvändiga anpassade modifierare för motsvarande parameter för den globala metoden. Om ett visst argument inte har några nödvändiga anpassade modifierare anger du null i stället för en matris med typer. Om den globala metoden inte har några argument, eller om inget av argumenten har nödvändiga anpassade modifierare, anger du null i stället för en matris med matriser.

optionalParameterTypeCustomModifiers
Type[][]

En matris med matriser av typer. Varje typmatris representerar de valfria anpassade modifierarna för motsvarande parameter. Om ett visst argument inte har några valfria anpassade modifierare anger du null i stället för en matris med typer. Om den globala metoden inte har några argument, eller om inget av argumenten har valfria anpassade modifierare, anger du null i stället för en matris med matriser.

Returer

Den definierade globala metoden.

Undantag

Metoden är inte statisk. Det innebär attributes att inte innehåller Static.

-eller-

Ett element i matrisen Type är null.

name är null.

Metoden CreateGlobalFunctions() har tidigare anropats.

Kommentarer

Den här överbelastningen tillhandahålls för designers av hanterade kompilatorer.

Du kan inte använda den globala metod som den här metoden definierar förrän du anropar CreateGlobalFunctions.

Gäller för

DefineGlobalMethod(String, MethodAttributes, Type, Type[])

Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs
Källa:
ModuleBuilder.cs

Definierar en global metod med angivet namn, attribut, returtyp och parametertyper.

public:
 System::Reflection::Emit::MethodBuilder ^ DefineGlobalMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, Type? returnType, Type[]? parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, Type returnType, Type[] parameterTypes);
member this.DefineGlobalMethod : string * System.Reflection.MethodAttributes * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineGlobalMethod (name As String, attributes As MethodAttributes, returnType As Type, parameterTypes As Type()) As MethodBuilder

Parametrar

name
String

Namnet på metoden. name kan inte innehålla inbäddade null-värden.

attributes
MethodAttributes

Metodens attribut. attributes måste innehålla Static.

returnType
Type

Metodens returtyp.

parameterTypes
Type[]

Typerna av metodens parametrar.

Returer

Den definierade globala metoden.

Undantag

Metoden är inte statisk. Det innebär attributes att inte innehåller Static.

-eller-

Längden name på är noll

-eller-

Ett element i matrisen Type är null.

name är null.

Exempel

I följande exempel visas hur du skapar DefineGlobalMethod en typoberoende metod som är kopplad till den aktuella ModuleBuilder. När du har skapat den globala metoden CreateGlobalFunctions måste anropas för att slutföra den.

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

Kommentarer

Den globala metod som den här metoden definierar kan inte användas förrän du anropar CreateGlobalFunctions.

Gäller för