ModuleBuilder.DefineGlobalMethod Méthode

Définition

Définit une méthode globale.

Surcharges

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

Définit une méthode globale à l'aide du nom, des attributs, du type de retour et des types de paramètres spécifiés.

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

Définit une méthode globale à l'aide du nom, des attributs, de la convention d'appel, du type de retour et des types de paramètres spécifiés.

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

Définit une méthode globale à l'aide du nom, des attributs, de la convention d'appel, du type de retour, des modificateurs personnalisés pour le type de retour, des types de paramètres et des modificateurs personnalisés pour les types de paramètres spécifiés.

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

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

Définit une méthode globale à l'aide du nom, des attributs, du type de retour et des 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);
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 des valeurs Null imbriqué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. C'est-à-dire que attributes n'inclut pas Static.

- ou -

La longueur de name est égale à zéro.

- ou -

Un élément du tableau Type est null.

name a la valeur null.

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

Exemples

L’exemple suivant illustre l’utilisation de DefineGlobalMethod pour créer une méthode indépendante du type liée au actuel ModuleBuilder. Après avoir créé la méthode globale, CreateGlobalFunctions doit être appelée pour la terminer.

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

Remarques

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

Notes

À compter du .NET Framework 2.0 Service Pack 1, ce membre n’a plus besoin de ReflectionPermission l’indicateur ReflectionPermissionFlag.ReflectionEmit . (Consultez Problèmes de sécurité dans l’émission de réflexion.) Pour utiliser cette fonctionnalité, votre application doit cibler .NET Framework 3.5 ou version ultérieure.

S’applique à

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

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

Définit une méthode globale à l'aide du nom, des attributs, de la convention d'appel, du type de retour et des 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);
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 des valeurs Null imbriquées.

attributes
MethodAttributes

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

callingConvention
CallingConventions

Convention d’appel de 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. C'est-à-dire que attributes n'inclut pas Static.

- ou -

Un élément du tableau Type est null.

name a la valeur null.

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

Exemples

L’exemple de code suivant illustre l’utilisation de DefineGlobalMethod pour créer une méthode indépendante du type liée au actuel ModuleBuilder. Après avoir créé la méthode globale, CreateGlobalFunctions doit être appelée pour la terminer.

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

Remarques

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

Notes

À compter du .NET Framework 2.0 Service Pack 1, ce membre n’a plus besoin de ReflectionPermission l’indicateur ReflectionPermissionFlag.ReflectionEmit . (Consultez Problèmes de sécurité dans l’émission de réflexion.) Pour utiliser cette fonctionnalité, votre application doit cibler .NET Framework 3.5 ou version ultérieure.

S’applique à

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

Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs
Source:
ModuleBuilder.cs

Définit une méthode globale à l'aide du nom, des attributs, de la convention d'appel, du type de retour, des modificateurs personnalisés pour le type de retour, des types de paramètres et des modificateurs personnalisés pour 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 ^> ^ 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

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 de la méthode.

returnType
Type

Type de retour de la méthode.

requiredReturnTypeCustomModifiers
Type[]

Tableau des types représentant les modificateurs personnalisés requis pour le type de retour, tels que IsConst ou IsBoxed. Si le type de retour ne possède pas de modificateur personnalisé requis, spécifiez null.

optionalReturnTypeCustomModifiers
Type[]

Tableau des types représentant les modificateurs personnalisés facultatifs pour le type de retour, tels que IsConst ou IsBoxed. Si le type de retour ne possède pas de 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 ne possède pas de modificateur personnalisé requis, spécifiez null plutôt qu'un tableau de types. Si la méthode globale ne possède pas d'argument, ou si aucun des arguments ne possède de modificateur personnalisé requis, spécifiez null plutôt qu'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 ne possède pas de modificateur personnalisé facultatif, spécifiez null plutôt qu'un tableau de types. Si la méthode globale ne possède pas d'argument, ou si aucun des arguments ne possède de modificateur personnalisé facultatif, spécifiez null plutôt qu'un tableau de tableaux.

Retours

Méthode globale définie.

Exceptions

La méthode n’est pas statique. C'est-à-dire que attributes n'inclut pas Static.

- ou -

Un élément du tableau Type est null.

name a la valeur null.

La méthode CreateGlobalFunctions() a été appelée au préalable.

Remarques

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

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

Notes

À compter du .NET Framework 2.0 Service Pack 1, ce membre n’a plus besoin de ReflectionPermission l’indicateur ReflectionPermissionFlag.ReflectionEmit . (Consultez Problèmes de sécurité dans l’émission de réflexion.) Pour utiliser cette fonctionnalité, votre application doit cibler .NET Framework 3.5 ou version ultérieure.

S’applique à