Aracılığıyla paylaş


ModuleBuilder.DefineGlobalMethod Yöntem

Tanım

Genel bir yöntem tanımlar.

Aşırı Yüklemeler

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

Belirtilen ada, özniteliklere, çağırma kuralına, dönüş türüne ve parametre türlerine sahip genel bir yöntem tanımlar.

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

Belirtilen ada, özniteliklere, çağırma kuralına, dönüş türüne, dönüş türü için özel değiştiricilere, parametre türlerine ve parametre türleri için özel değiştiricilere sahip genel bir yöntem tanımlar.

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

Belirtilen ada, özniteliklere, dönüş türüne ve parametre türlerine sahip genel bir yöntem tanımlar.

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

Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs

Belirtilen ada, özniteliklere, çağırma kuralına, dönüş türüne ve parametre türlerine sahip genel bir yöntem tanımlar.

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

Parametreler

name
String

Yöntemin adı. name katıştırılmış null değerleri içeremez.

attributes
MethodAttributes

yönteminin öznitelikleri. attributes içermelidir Static.

callingConvention
CallingConventions

yöntemi için çağırma kuralı.

returnType
Type

yönteminin dönüş türü.

parameterTypes
Type[]

Yöntemin parametrelerinin türleri.

Döndürülenler

Tanımlanan genel yöntem.

Özel durumlar

Yöntemi statik değil. Bu, attributes içermez Static.

-veya-

Dizideki Type bir öğe şeklindedir null.

name, null değeridir.

Örnekler

Aşağıdaki kod örneği, geçerli ModuleBuilderöğesine bağlı türünden bağımsız bir yöntem oluşturmak için uygulamasının kullanımını DefineGlobalMethod gösterir. Genel yöntemi derledikten sonra tamamlamak CreateGlobalFunctions için çağrılmalıdır.

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

Açıklamalar

çağırana CreateGlobalFunctionskadar bu yöntemin tanımladığı genel yöntemi kullanamazsınız.

Not

.NET Framework 2.0 Service Pack 1'den başlayarak, bu üye artık bayrağını ReflectionPermissionFlag.ReflectionEmit gerektirmezReflectionPermission. (Bkz. Yansıma Yaymada Güvenlik Sorunları.) Bu işlevselliği kullanmak için uygulamanızın .NET Framework 3.5 veya sonraki bir sürümü hedeflemesi gerekir.

Şunlara uygulanır

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

Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs

Belirtilen ada, özniteliklere, çağırma kuralına, dönüş türüne, dönüş türü için özel değiştiricilere, parametre türlerine ve parametre türleri için özel değiştiricilere sahip genel bir yöntem tanımlar.

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

Parametreler

name
String

Yöntemin adı. name eklenmiş null karakterler içeremez.

attributes
MethodAttributes

yönteminin öznitelikleri. attributes içermelidir Static.

callingConvention
CallingConventions

yöntemi için çağırma kuralı.

returnType
Type

yönteminin dönüş türü.

requiredReturnTypeCustomModifiers
Type[]

veya IsBoxedgibi IsConst dönüş türü için gerekli özel değiştiricileri temsil eden bir tür dizisi. Dönüş türünde gerekli özel değiştirici yoksa belirtin null.

optionalReturnTypeCustomModifiers
Type[]

veya IsBoxedgibi IsConst dönüş türü için isteğe bağlı özel değiştiricileri temsil eden bir tür dizisi. Dönüş türünde isteğe bağlı özel değiştirici yoksa belirtin null.

parameterTypes
Type[]

Yöntemin parametrelerinin türleri.

requiredParameterTypeCustomModifiers
Type[][]

Tür dizileri dizisi. Her tür dizisi, genel yöntemin ilgili parametresi için gerekli özel değiştiricileri temsil eder. Belirli bir bağımsız değişkenin gerekli özel değiştiricisi yoksa, bir tür dizisi yerine belirtin null . Genel yöntemin bağımsız değişkeni yoksa veya bağımsız değişkenlerin hiçbirinin özel değiştiricileri gerekli değilse, dizi dizisi yerine belirtin null .

optionalParameterTypeCustomModifiers
Type[][]

Tür dizileri dizisi. Her tür dizisi, ilgili parametre için isteğe bağlı özel değiştiricileri temsil eder. Belirli bir bağımsız değişkenin isteğe bağlı özel değiştiricisi yoksa, bir tür dizisi yerine belirtin null . Genel yöntemin bağımsız değişkeni yoksa veya bağımsız değişkenlerin hiçbirinin isteğe bağlı özel değiştiricileri yoksa, dizi dizisi yerine belirtin null .

Döndürülenler

Tanımlanan genel yöntem.

Özel durumlar

Yöntemi statik değil. Bu, attributes içermez Static.

-veya-

Dizideki Type bir öğe şeklindedir null.

name, null değeridir.

Yöntemi CreateGlobalFunctions() daha önce çağrıldı.

Açıklamalar

Bu aşırı yükleme, yönetilen derleyici tasarımcıları için sağlanır.

çağırana CreateGlobalFunctionskadar bu yöntemin tanımladığı genel yöntemi kullanamazsınız.

Not

.NET Framework 2.0 Service Pack 1'den başlayarak, bu üye artık bayrağını ReflectionPermissionFlag.ReflectionEmit gerektirmezReflectionPermission. (Bkz. Yansıma Yaymada Güvenlik Sorunları.) Bu işlevselliği kullanmak için uygulamanızın .NET Framework 3.5 veya sonraki bir sürümü hedeflemesi gerekir.

Şunlara uygulanır

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

Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs
Kaynak:
ModuleBuilder.cs

Belirtilen ada, özniteliklere, dönüş türüne ve parametre türlerine sahip genel bir yöntem tanımlar.

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

Parametreler

name
String

Yöntemin adı. name katıştırılmış null değerleri içeremez.

attributes
MethodAttributes

yönteminin öznitelikleri. attributes içermelidir Static.

returnType
Type

yönteminin dönüş türü.

parameterTypes
Type[]

Yöntemin parametrelerinin türleri.

Döndürülenler

Tanımlanan genel yöntem.

Özel durumlar

Yöntemi statik değil. Bu, attributes içermez Static.

-veya-

uzunluğu name sıfırdır

-veya-

Dizideki Type bir öğe şeklindedir null.

name, null değeridir.

Örnekler

Aşağıdaki örnekte, geçerli ModuleBuilderöğesine bağlı tür bağımsız bir yöntem oluşturmak için kullanımı DefineGlobalMethod gösterilmektedir. Genel yöntemi derledikten sonra tamamlamak CreateGlobalFunctions için çağrılmalıdır.

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

Açıklamalar

Bu yöntemin tanımladığı genel yöntem, çağırana CreateGlobalFunctionskadar kullanılamaz.

Not

.NET Framework 2.0 Service Pack 1'den başlayarak, bu üye artık bayrağını ReflectionPermissionFlag.ReflectionEmit gerektirmezReflectionPermission. (Bkz. Yansıma Yaymada Güvenlik Sorunları.) Bu işlevselliği kullanmak için uygulamanızın .NET Framework 3.5 veya sonraki bir sürümü hedeflemesi gerekir.

Şunlara uygulanır