ModuleBuilder.DefineGlobalMethod Méthode

Définition

Définit une méthode globale.

Surcharges

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

Définit une méthode globale avec le nom, les attributs, le type de retour et les types de paramètres spécifiés.

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

Définit une méthode globale avec le nom, les attributs, la convention d’appel, le type de retour et les types de paramètres spécifiés.

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

Définit une méthode globale avec le nom, les attributs, la convention d’appel, le type de retour, les modificateurs personnalisés pour le type de retour, les types de paramètres et les modificateurs personnalisés pour les types de paramètres.

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

Définit une méthode globale avec le nom, les attributs, le type de retour et les types de paramètres spécifiés.

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

Paramètres

name
String

Nom de la méthode. name ne peut pas contenir de valeurs Null incorporées.

attributes
MethodAttributes

Attributs de la méthode. attributes doit inclure Static.

returnType
Type

Type de retour de la méthode.

parameterTypes
Type[]

Types des paramètres de la méthode.

Retours

Méthode globale définie.

Exceptions

La méthode n’est pas statique. Autrement dit, attributes n’inclut Staticpas .

-ou-

La longueur est égale name à zéro

-ou-

Un élément dans le Type tableau est null.

name a la valeur null.

CreateGlobalFunctions() a été appelé précédemment.

Exemples

L’exemple suivant illustre l’utilisation d’une DefineGlobalMethod méthode indépendante du type liée à l’actuel ModuleBuilder. Après avoir généré la méthode globale, CreateGlobalFunctions vous devez l’appeler pour le terminer.

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

Remarques

La méthode globale que cette méthode définit n’est pas utilisable tant que vous n’appelez CreateGlobalFunctionspas .

S’applique à

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

Définit une méthode globale avec le nom, les attributs, la convention d’appel, le type de retour et les types de paramètres spécifiés.

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

Paramètres

name
String

Nom de la méthode. name ne peut pas contenir de valeurs Null incorporées.

attributes
MethodAttributes

Attributs de la méthode. attributes doit inclure Static.

callingConvention
CallingConventions

Convention d’appel pour la méthode.

returnType
Type

Type de retour de la méthode.

parameterTypes
Type[]

Types des paramètres de la méthode.

Retours

Méthode globale définie.

Exceptions

La méthode n’est pas statique. Autrement dit, attributes n’inclut Staticpas .

-ou-

Un élément dans le Type tableau est null.

name a la valeur null.

CreateGlobalFunctions() a été appelé précédemment.

Exemples

L’exemple de code suivant illustre l’utilisation d’une DefineGlobalMethod méthode indépendante du type liée au code actuel ModuleBuilder. Après avoir généré la méthode globale, CreateGlobalFunctions vous devez l’appeler pour le terminer.

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

Remarques

Vous ne pouvez pas utiliser la méthode globale que cette méthode définit tant que vous n’appelez CreateGlobalFunctionspas .

S’applique à

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

Définit une méthode globale avec le nom, les attributs, la convention d’appel, le type de retour, les modificateurs personnalisés pour le type de retour, les types de paramètres et les modificateurs personnalisés pour les types de paramètres.

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

Paramètres

name
String

Nom de la méthode. name ne peut pas contenir de caractères null incorporés.

attributes
MethodAttributes

Attributs de la méthode. attributes doit inclure Static.

callingConvention
CallingConventions

Convention d’appel pour la méthode.

returnType
Type

Type de retour de la méthode.

requiredReturnTypeCustomModifiers
Type[]

Tableau de types représentant les modificateurs personnalisés requis pour le type de retour, tel que IsConst ou IsBoxed. Si le type de retour n’a pas de modificateurs personnalisés requis, spécifiez null.

optionalReturnTypeCustomModifiers
Type[]

Tableau de types représentant les modificateurs personnalisés facultatifs pour le type de retour, tel que IsConst ou IsBoxed. Si le type de retour n’a aucun modificateur personnalisé facultatif, spécifiez null.

parameterTypes
Type[]

Types des paramètres de la méthode.

requiredParameterTypeCustomModifiers
Type[][]

Tableau de tableaux de types. Chaque tableau de types représente les modificateurs personnalisés requis pour le paramètre correspondant de la méthode globale. Si un argument particulier n’a pas de modificateurs personnalisés requis, spécifiez null au lieu d’un tableau de types. Si la méthode globale n’a aucun argument ou si aucun des arguments n’a besoin de modificateurs personnalisés, spécifiez null au lieu d’un tableau de tableaux.

optionalParameterTypeCustomModifiers
Type[][]

Tableau de tableaux de types. Chaque tableau de types représente les modificateurs personnalisés facultatifs pour le paramètre correspondant. Si un argument particulier n’a aucun modificateur personnalisé facultatif, spécifiez null au lieu d’un tableau de types. Si la méthode globale n’a aucun argument ou si aucun argument n’a de modificateurs personnalisés facultatifs, spécifiez null au lieu d’un tableau de tableaux.

Retours

Méthode globale définie.

Exceptions

La méthode n’est pas statique. Autrement dit, attributes n’inclut Staticpas .

-ou-

Un élément dans le Type tableau est null.

name a la valeur null.

La CreateGlobalFunctions() méthode a été appelée précédemment.

Remarques

Cette surcharge est fournie pour les concepteurs de compilateurs managés.

Vous ne pouvez pas utiliser la méthode globale que cette méthode définit tant que vous n’appelez CreateGlobalFunctionspas .

S’applique à