ModuleBuilder.DefineGlobalMethod Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Definuje globální metodu.
Přetížení
| Name | Description |
|---|---|
| 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 návratového typu, typy parametrů a vlastními modifikátory pro typy parametrů. |
| 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[])
- Zdroj:
- ModuleBuilder.cs
- Zdroj:
- ModuleBuilder.cs
- 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.
attributes musí 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
name je null.
CreateGlobalFunctions() byl dříve volána.
Příklady
Následující ukázka kódu ukazuje použití DefineGlobalMethod k vytvoření metody nezávislé na typu svázané s aktuální ModuleBuilder. Po sestavení globální metody musí být volána, CreateGlobalFunctions aby bylo možné ji dokončit.
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.
Platí pro
DefineGlobalMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
- Zdroj:
- ModuleBuilder.cs
- Zdroj:
- ModuleBuilder.cs
- 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 návratového typu, typy parametrů a vlastními 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 nemůže obsahovat vložené znaky null.
- attributes
- MethodAttributes
Atributy metody.
attributes musí obsahovat Static.
- callingConvention
- CallingConventions
Konvence volání pro metodu.
- returnType
- Type
Návratový typ metody.
- requiredReturnTypeCustomModifiers
- Type[]
Pole typů představujících požadované vlastní modifikátory návratového typu, například IsConst nebo IsBoxed. Pokud návratový typ neobsahuje žá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 neobsahuje žá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 neobsahuje žádné požadované vlastní modifikátory, zadejte null místo pole typů. Pokud globální metoda nemá žádné argumenty nebo pokud žádný z argumentů nepožadoval vlastní modifikátory, zadejte null místo pole polí.
- optionalParameterTypeCustomModifiers
- Type[][]
Pole polí typů. Každé pole typů představuje volitelné vlastní modifikátory pro odpovídající parametr. 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
name je null.
Metoda CreateGlobalFunctions() byla dříve volána.
Poznámky
Toto přetížení je poskytováno pro návrháře spravovaných kompilátorů.
Nelze použít globální metodu, kterou tato metoda definuje, dokud nevoláte CreateGlobalFunctions.
Platí pro
DefineGlobalMethod(String, MethodAttributes, Type, Type[])
- Zdroj:
- ModuleBuilder.cs
- Zdroj:
- ModuleBuilder.cs
- 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.
attributes musí 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 name je nula.
nebo
Prvek v Type poli je null.
name je null.
CreateGlobalFunctions() byl dříve volána.
Příklady
Následující příklad znázorňuje použití DefineGlobalMethod k vytvoření metody nezávislé na typu svázané s aktuální ModuleBuilder. Po sestavení globální metody musí být volána, CreateGlobalFunctions aby bylo možné ji dokončit.
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 nevoláte CreateGlobalFunctions.