ModuleBuilder.DefineGlobalMethod Metódus

Definíció

Globális metódust definiál.

Túlterhelések

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

Definiál egy globális metódust a megadott névvel, attribútumokkal, hívási konvencióval, visszatérési típussal és paramétertípusokkal.

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

Definiál egy globális metódust a megadott névvel, attribútumokkal, hívási konvencióval, visszatérési típussal, a visszatérési típus egyéni módosítóival, a paramétertípusok paramétertípusaival és egyéni módosítóival.

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

Definiál egy globális metódust a megadott névvel, attribútumokkal, visszatérési típussal és paramétertípusokkal.

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

Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs

Definiál egy globális metódust a megadott névvel, attribútumokkal, hívási konvencióval, visszatérési típussal és paramétertípusokkal.

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éterek

name
String

A metódus neve. name nem tartalmazhat beágyazott null értékeket.

attributes
MethodAttributes

A metódus attribútumai. attributestartalmaznia kell a .Static

callingConvention
CallingConventions

A metódus hívási konvenciója.

returnType
Type

A metódus visszatérési típusa.

parameterTypes
Type[]

A metódus paramétereinek típusai.

Válaszok

A definiált globális módszer.

Kivételek

A metódus nem statikus. Ez azt jelenti, attributes hogy nem tartalmazza Static.

-vagy-

A tömb egyik eleme az Typenull.

name az null.

Példák

Az alábbi kódminta az DefineGlobalMethod aktuálishoz ModuleBuilderkötött típusfüggetlen metódus létrehozását mutatja be. A globális metódus CreateGlobalFunctions létrehozása után meg kell hívni annak befejezéséhez.

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

Megjegyzések

Nem használhatja a metódus által definiált globális metódust, amíg meg nem hívja CreateGlobalFunctions.

A következőre érvényes:

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

Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs

Definiál egy globális metódust a megadott névvel, attribútumokkal, hívási konvencióval, visszatérési típussal, a visszatérési típus egyéni módosítóival, a paramétertípusok paramétertípusaival és egyéni módosítóival.

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éterek

name
String

A metódus neve. name nem tartalmazhat beágyazott null karaktereket.

attributes
MethodAttributes

A metódus attribútumai. attributestartalmaznia kell a .Static

callingConvention
CallingConventions

A metódus hívási konvenciója.

returnType
Type

A metódus visszatérési típusa.

requiredReturnTypeCustomModifiers
Type[]

A visszatérési típushoz szükséges egyéni módosítókat képviselő típusok tömbje, például IsConst vagy IsBoxed. Ha a visszatérési típus nem rendelkezik kötelező egyéni módosítókkal, adja meg a .null

optionalReturnTypeCustomModifiers
Type[]

A visszatérési típus opcionális egyéni módosítóit képviselő típusok tömbje, például IsConst vagy IsBoxed. Ha a visszatérési típus nem tartalmaz opcionális egyéni módosítókat, adja meg a következőt null:

parameterTypes
Type[]

A metódus paramétereinek típusai.

requiredParameterTypeCustomModifiers
Type[][]

Típustömbök tömbje. Minden típusok tömbje a globális metódus megfelelő paraméteréhez szükséges egyéni módosítókat jelöli. Ha egy adott argumentum nem rendelkezik kötelező egyéni módosítókkal, adja meg null a típusok tömbje helyett. Ha a globális metódus nem rendelkezik argumentumokkal, vagy ha egyik argumentum sem igényel egyéni módosítókat, tömbtömb helyett adja meg null .

optionalParameterTypeCustomModifiers
Type[][]

Típustömbök tömbje. Az egyes típusok tömbje a megfelelő paraméter opcionális egyéni módosítóit jelöli. Ha egy adott argumentum nem rendelkezik választható egyéni módosítókkal, adja meg null a típusok tömbje helyett. Ha a globális metódus nem rendelkezik argumentumokkal, vagy ha egyik argumentum sem rendelkezik választható egyéni módosítókkal, tömbtömb helyett adja meg null .

Válaszok

A definiált globális módszer.

Kivételek

A metódus nem statikus. Ez azt jelenti, attributes hogy nem tartalmazza Static.

-vagy-

A tömb egyik eleme az Typenull.

name az null.

A CreateGlobalFunctions() metódust korábban meghívták.

Megjegyzések

Ez a túlterhelés a felügyelt fordítók tervezői számára biztosított.

Nem használhatja a metódus által definiált globális metódust, amíg meg nem hívja CreateGlobalFunctions.

A következőre érvényes:

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

Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs
Forrás:
ModuleBuilder.cs

Definiál egy globális metódust a megadott névvel, attribútumokkal, visszatérési típussal és paramétertípusokkal.

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éterek

name
String

A metódus neve. name nem tartalmazhat beágyazott null értékeket.

attributes
MethodAttributes

A metódus attribútumai. attributestartalmaznia kell a .Static

returnType
Type

A metódus visszatérési típusa.

parameterTypes
Type[]

A metódus paramétereinek típusai.

Válaszok

A definiált globális módszer.

Kivételek

A metódus nem statikus. Ez azt jelenti, attributes hogy nem tartalmazza Static.

-vagy-

A hossz name nulla

-vagy-

A tömb egyik eleme az Typenull.

name az null.

Példák

Az alábbi példa bemutatja, hogy az DefineGlobalMethod aktuálishoz ModuleBuilderkötött típusfüggetlen metódust kell létrehozni. A globális metódus CreateGlobalFunctions létrehozása után meg kell hívni annak befejezéséhez.

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

Megjegyzések

A metódus által definiált globális metódus csak akkor használható, ha meghívja CreateGlobalFunctions.

A következőre érvényes: