ModuleBuilder.DefineGlobalMethod Metoda

Definice

Definuje globální metodu.

Přetížení

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

Definuje globální metodu se zadaným názvem, atributy, návratovým typem a typy parametrů.

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

Definuje globální metodu se zadaným názvem, atributy, konvencí volání, návratovým typem a typy parametrů.

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

Definuje globální metodu se zadaným názvem, atributy, konvencí volání, návratovým typem, vlastními modifikátory pro návratový typ, typy parametrů a vlastní modifikátory pro typy parametrů.

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

Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs

Definuje globální metodu se zadaným názvem, atributy, návratovým typem a typy parametrů.

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

Parametry

name
String

Název metody name nemůže obsahovat vložené hodnoty null.

attributes
MethodAttributes

Atributy metody. attributesmusí obsahovat .Static

returnType
Type

Návratový typ metody.

parameterTypes
Type[]

Typy parametrů metody

Návraty

Definovaná globální metoda.

Výjimky

Metoda není statická. To znamená, attributes že nezahrnuje Static.

-nebo-

Délka je name nula.

-nebo-

Prvek v Type poli je null.

name je null.

Příklady

Následující příklad znázorňuje použití DefineGlobalMethod k vytvoření metody nezávislé na typu vázanou na aktuální ModuleBuilder. Po sestavení globální metody CreateGlobalFunctions musí být volána, aby se dokončila.

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

Poznámky

Globální metoda, kterou tato metoda definuje, není použitelná, dokud nezavoláte CreateGlobalFunctions.

Poznámka

Počínaje .NET Framework 2.0 Service Pack 1, tento člen již nevyžaduje ReflectionPermission s příznakem ReflectionPermissionFlag.ReflectionEmit . (Viz Problémy se zabezpečením v reflexi Emit.) Pokud chcete tuto funkci používat, měla by vaše aplikace cílit na rozhraní .NET Framework 3.5 nebo novější.

Platí pro

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

Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs

Definuje globální metodu se zadaným názvem, atributy, konvencí volání, návratovým typem a typy parametrů.

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

Parametry

name
String

Název metody name nemůže obsahovat vložené hodnoty null.

attributes
MethodAttributes

Atributy metody. attributesmusí obsahovat .Static

callingConvention
CallingConventions

Konvence volání pro metodu

returnType
Type

Návratový typ metody.

parameterTypes
Type[]

Typy parametrů metody

Návraty

Definovaná globální metoda.

Výjimky

Metoda není statická. To znamená, attributes že nezahrnuje Static.

-nebo-

Prvek v Type poli je null.

name je null.

Příklady

Následující ukázka kódu ukazuje použití DefineGlobalMethod metody k vytvoření metody nezávislé na typu vázanou na aktuální ModuleBuilder. Po sestavení globální metody CreateGlobalFunctions musí být volána, aby se dokončila.

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

Poznámky

Nelze použít globální metodu, kterou tato metoda definuje, dokud nevoláte CreateGlobalFunctions.

Poznámka

Počínaje .NET Framework 2.0 Service Pack 1, tento člen již nevyžaduje ReflectionPermission s příznakem ReflectionPermissionFlag.ReflectionEmit . (Viz Problémy se zabezpečením v reflexi Emit.) Pokud chcete tuto funkci používat, měla by vaše aplikace cílit na rozhraní .NET Framework 3.5 nebo novější.

Platí pro

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

Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs
Zdroj:
ModuleBuilder.cs

Definuje globální metodu se zadaným názvem, atributy, konvencí volání, návratovým typem, vlastními modifikátory pro návratový typ, typy parametrů a vlastní modifikátory pro typy parametrů.

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

Parametry

name
String

Název metody name nesmí obsahovat vložené znaky null.

attributes
MethodAttributes

Atributy metody. attributesmusí obsahovat .Static

callingConvention
CallingConventions

Konvence volání pro metodu

returnType
Type

Návratový typ metody.

requiredReturnTypeCustomModifiers
Type[]

Pole typů představující požadované vlastní modifikátory pro návratový typ, například IsConst nebo IsBoxed. Pokud návratový typ nemá žádné požadované vlastní modifikátory, zadejte null.

optionalReturnTypeCustomModifiers
Type[]

Pole typů představujících volitelné vlastní modifikátory návratového typu, například IsConst nebo IsBoxed. Pokud návratový typ nemá žádné volitelné vlastní modifikátory, zadejte null.

parameterTypes
Type[]

Typy parametrů metody

requiredParameterTypeCustomModifiers
Type[][]

Pole polí typů. Každé pole typů představuje požadované vlastní modifikátory pro odpovídající parametr globální metody. Pokud určitý argument nemá žádné požadované vlastní modifikátory, zadejte null místo pole typů. Pokud globální metoda nemá žádné argumenty nebo pokud žádný z argumentů nevyžaduje vlastní modifikátory, zadejte null místo pole polí.

optionalParameterTypeCustomModifiers
Type[][]

Pole polí typů. Každé pole typů představuje volitelné vlastní modifikátory odpovídajícího parametru. Pokud určitý argument nemá žádné volitelné vlastní modifikátory, zadejte null místo pole typů. Pokud globální metoda nemá žádné argumenty nebo pokud žádný z argumentů nemá volitelné vlastní modifikátory, zadejte null místo pole polí.

Návraty

Definovaná globální metoda.

Výjimky

Metoda není statická. To znamená, attributes že nezahrnuje Static.

-nebo-

Prvek v Type poli je null.

name je null.

Metoda CreateGlobalFunctions() byla dříve volána.

Poznámky

Toto přetížení je k dispozici pro návrháře spravovaných kompilátorů.

Nelze použít globální metodu, kterou tato metoda definuje, dokud nevoláte CreateGlobalFunctions.

Poznámka

Počínaje .NET Framework 2.0 Service Pack 1, tento člen již nevyžaduje ReflectionPermission s příznakem ReflectionPermissionFlag.ReflectionEmit . (Viz Problémy se zabezpečením v reflexi Emit.) Pokud chcete tuto funkci používat, měla by vaše aplikace cílit na rozhraní .NET Framework 3.5 nebo novější.

Platí pro