ModuleBuilder.GetArrayMethod(Type, String, CallingConventions, Type, Type[]) Método
Definição
Retorna o método nomeado em uma classe de matriz.Returns the named method on an array class.
public:
System::Reflection::MethodInfo ^ GetArrayMethod(Type ^ arrayClass, System::String ^ methodName, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.MethodInfo GetArrayMethod (Type arrayClass, string methodName, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes);
public System.Reflection.MethodInfo GetArrayMethod (Type arrayClass, string methodName, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes);
member this.GetArrayMethod : Type * string * System.Reflection.CallingConventions * Type * Type[] -> System.Reflection.MethodInfo
Public Function GetArrayMethod (arrayClass As Type, methodName As String, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type()) As MethodInfo
Parâmetros
- arrayClass
- Type
Uma classe de matriz.An array class.
- methodName
- String
O nome de um método na classe de matriz.The name of a method on the array class.
- callingConvention
- CallingConventions
A convenção de chamada do método.The method's calling convention.
- returnType
- Type
O tipo de retorno do método.The return type of the method.
- parameterTypes
- Type[]
Os tipos de parâmetros do método.The types of the method's parameters.
Retornos
O método nomeado em uma classe de matriz.The named method on an array class.
Exceções
arrayClass não é uma matriz.arrayClass is not an array.
arrayClass ou methodName é null.arrayClass or methodName is null.
Exemplos
O exemplo a seguir demonstra como usar GetArrayMethod o para obter o MethodInfo correspondente a um método que retorna um valor de matriz.The following example demonstrates how to use GetArrayMethod to obtain the MethodInfo corresponding to a method that returns an array value.
// 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 = {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.
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()
Comentários
GetArrayMethod é útil quando você tem uma matriz de um tipo cuja definição não foi concluída e você deseja acessar os métodos definidos em Array .GetArrayMethod is useful when you have an array of a type whose definition has not been completed and you want to access methods defined on Array. Por exemplo, você pode definir um tipo e desejar definir um método que usa uma matriz do tipo como um parâmetro.For example, you might define a type and want to define a method that takes an array of the type as a parameter. Para acessar os elementos da matriz, você precisará chamar métodos da Array classe.In order to access the elements of the array, you will need to call methods of the Array class.