Freigeben über


ModuleBuilder.GetArrayMethodToken-Methode

Gibt das Token für die benannte Methode einer Arrayklasse zurück.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function GetArrayMethodToken ( _
    arrayClass As Type, _
    methodName As String, _
    callingConvention As CallingConventions, _
    returnType As Type, _
    parameterTypes As Type() _
) As MethodToken
'Usage
Dim instance As ModuleBuilder
Dim arrayClass As Type
Dim methodName As String
Dim callingConvention As CallingConventions
Dim returnType As Type
Dim parameterTypes As Type()
Dim returnValue As MethodToken

returnValue = instance.GetArrayMethodToken(arrayClass, methodName, callingConvention, returnType, parameterTypes)
public MethodToken GetArrayMethodToken (
    Type arrayClass,
    string methodName,
    CallingConventions callingConvention,
    Type returnType,
    Type[] parameterTypes
)
public:
MethodToken GetArrayMethodToken (
    Type^ arrayClass, 
    String^ methodName, 
    CallingConventions callingConvention, 
    Type^ returnType, 
    array<Type^>^ parameterTypes
)
public MethodToken GetArrayMethodToken (
    Type arrayClass, 
    String methodName, 
    CallingConventions callingConvention, 
    Type returnType, 
    Type[] parameterTypes
)
public function GetArrayMethodToken (
    arrayClass : Type, 
    methodName : String, 
    callingConvention : CallingConventions, 
    returnType : Type, 
    parameterTypes : Type[]
) : MethodToken

Parameter

  • arrayClass
    Das Type-Objekt für das Array.
  • methodName
    Eine Zeichenfolge, die den Namen der Methode enthält.
  • callingConvention
    Die Aufrufkonvention für die Methode.
  • returnType
    Der Rückgabetyp der Methode.
  • parameterTypes
    Die Typen der Parameter für die Methode.

Rückgabewert

Das Token für die benannte Methode einer Arrayklasse.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

arrayClass ist kein Array.

- oder -

Die Länge von methodName ist 0.

ArgumentNullException

arrayClass oder methodName ist NULL (Nothing in Visual Basic).

Hinweise

Diese Methode ist GetArrayMethod ähnlich. Sie gibt jedoch statt der Methode selbst das Token für die Arraymethode zurück.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit GetArrayMethod die MethodToken abgerufen wird, die einer Methode entspricht, die einen Arraywert zurückgibt.

' Define a dynamic module in "TempAssembly" assembly.
Dim myModuleBuilder As ModuleBuilder = myAssemblyBuilder.DefineDynamicModule("TempModule")
' Define a runtime class with specified name and attributes.
Dim myTypeBuilder As TypeBuilder = _
            myModuleBuilder.DefineType("TempClass", TypeAttributes.Public)
Dim myParamArray() As Type = New Type() {GetType(Array)}
' Add 'SortArray' method to the class, with the given signature.
Dim myMethod As MethodBuilder = _
   myTypeBuilder.DefineMethod("SortArray", MethodAttributes.Public, _
   GetType(Array), myParamArray)

Dim myArrayClass(0) As Type
Dim parameterTypes() As Type = New Type() {GetType(Array)}
' Get the 'MethodInfo' object corresponding to 'Sort' method of 'Array' class.
Dim myMethodInfo As MethodInfo = _
   myModuleBuilder.GetArrayMethod(myArrayClass.GetType(), "Sort", _
   CallingConventions.Standard, Nothing, parameterTypes)
' Get the token corresponding to 'Sort' method of 'Array' class.
Dim myMethodToken As MethodToken = _
      myModuleBuilder.GetArrayMethodToken(myArrayClass.GetType(), _
      "Sort", CallingConventions.Standard, Nothing, parameterTypes)
Console.WriteLine("Token used by module to identify the 'Sort' method" + _
                  " of 'Array' class is : {0:x} ", myMethodToken.Token)
Dim methodIL As ILGenerator = myMethod.GetILGenerator()
methodIL.Emit(OpCodes.Ldarg_1)
methodIL.Emit(OpCodes.Call, myMethodInfo)
methodIL.Emit(OpCodes.Ldarg_1)
methodIL.Emit(OpCodes.Ret)
' Complete the creation of type.
myTypeBuilder.CreateType()
// Define a dynamic module in "TempAssembly" assembly.
ModuleBuilder myModuleBuilder = myAssemblyBuilder.
                              DefineDynamicModule("TempModule");
// Define a runtime class with specified name and attributes.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType
                           ("TempClass",TypeAttributes.Public);
Type[] paramArray = {typeof(Array)};
// Add 'SortArray' method to the class, with the given signature.
MethodBuilder myMethod = myTypeBuilder.DefineMethod("SortArray", 
                          MethodAttributes.Public,typeof(Array),paramArray);

Type[] myArrayClass = new Type[1];
Type[] parameterTypes = {typeof(Array)};
// Get the 'MethodInfo' object corresponding to 'Sort' method of 'Array' class.
MethodInfo myMethodInfo=myModuleBuilder.GetArrayMethod(
            myArrayClass.GetType(),"Sort",CallingConventions.Standard,
                                                                         null,parameterTypes);
// Get the token corresponding to 'Sort' method of 'Array' class.
MethodToken myMethodToken=myModuleBuilder.GetArrayMethodToken(
            myArrayClass.GetType(),"Sort",CallingConventions.Standard,
                                                                        null,parameterTypes);
Console.WriteLine("Token used by module to identify the 'Sort' method"
                            + " of 'Array' class is : {0:x} ",myMethodToken.Token);

ILGenerator methodIL = myMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ldarg_1);
methodIL.Emit(OpCodes.Call,myMethodInfo);
methodIL.Emit(OpCodes.Ldarg_1);
methodIL.Emit(OpCodes.Ret);

// Complete the creation of type.
myTypeBuilder.CreateType();
// Define a dynamic module in "TempAssembly" assembly.
ModuleBuilder^ myModuleBuilder = myAssemblyBuilder->
   DefineDynamicModule( "TempModule" );

// Define a runtime class with specified name and attributes.
TypeBuilder^ myTypeBuilder = myModuleBuilder->DefineType(
   "TempClass", TypeAttributes::Public );
array<Type^>^ paramArray = { Array::typeid };
// Add 'SortArray' method to the class, with the given signature.
MethodBuilder^ myMethod = myTypeBuilder->DefineMethod( "SortArray",
   MethodAttributes::Public, Array::typeid, paramArray );

array<Type^>^ myArrayClass = gcnew array<Type^>( 1 );
array<Type^>^ parameterTypes = { Array::typeid };
// Get the 'MethodInfo' object corresponding to 'Sort' method of 'Array' class.
MethodInfo^ myMethodInfo = myModuleBuilder->GetArrayMethod(
   myArrayClass->GetType(), "Sort", CallingConventions::Standard,
   nullptr, parameterTypes );

// Get the token corresponding to 'Sort' method of 'Array' class.
MethodToken myMethodToken = myModuleBuilder->GetArrayMethodToken(
   myArrayClass->GetType(), "Sort", CallingConventions::Standard,
   nullptr, parameterTypes );
Console::WriteLine( "Token used by module to identify the 'Sort' method"
   + " of 'Array' class is : {0:x} ", myMethodToken.Token );

ILGenerator^ methodIL = myMethod->GetILGenerator();
methodIL->Emit( OpCodes::Ldarg_1 );
methodIL->Emit( OpCodes::Call, myMethodInfo );
methodIL->Emit( OpCodes::Ldarg_1 );
methodIL->Emit( OpCodes::Ret );

// Complete the creation of type.
myTypeBuilder->CreateType();
// Define a dynamic module in "TempAssembly" assembly.
ModuleBuilder myModuleBuilder = myAssemblyBuilder.DefineDynamicModule(
    "TempModule");

// Define a runtime class with specified name and attributes.
TypeBuilder myTypeBuilder = myModuleBuilder.DefineType("TempClass",
    TypeAttributes.Public);
Type paramArray[] = { Array.class.ToType() };

// Add 'SortArray' method to the class, with the given signature.
MethodBuilder myMethod = myTypeBuilder.DefineMethod("SortArray", 
    MethodAttributes.Public, Array.class.ToType(), paramArray);

Type myArrayClass[] = new Type[1];
Type parameterTypes[] = { Array.class.ToType() };

// Get the 'MethodInfo' object corresponding to 
// 'Sort' method of 'Array' class.
MethodInfo myMethodInfo = myModuleBuilder.GetArrayMethod(
    myArrayClass.GetType(), "Sort", CallingConventions.Standard, null,
    parameterTypes);

// Get the token corresponding to 'Sort' method of 'Array' class.
MethodToken myMethodToken = myModuleBuilder.GetArrayMethodToken(
    myArrayClass.GetType(), "Sort", CallingConventions.Standard, null, 
    parameterTypes);
Console.WriteLine("Token used by module to identify the 'Sort' method " 
    + "of 'Array' class is : {0:x} ", (Int32)myMethodToken.get_Token());

ILGenerator methodIL = myMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ldarg_1);
methodIL.Emit(OpCodes.Call, myMethodInfo);
methodIL.Emit(OpCodes.Ldarg_1);
methodIL.Emit(OpCodes.Ret);

// Complete the creation of type.
myTypeBuilder.CreateType();

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ModuleBuilder-Klasse
ModuleBuilder-Member
System.Reflection.Emit-Namespace