ModuleBuilder.GetArrayMethod Method (Type, String, CallingConventions, Type, Type())


Returns the named method on an array class.

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

Public Function GetArrayMethod (
	arrayClass As Type,
	methodName As String,
	callingConvention As CallingConventions,
	returnType As Type,
	parameterTypes As Type()
) As MethodInfo


Type: System.Type

An array class.

Type: System.String

The name of a method on the array class.

Type: System.Reflection.CallingConventions

The method's calling convention.

Type: System.Type

The return type of the method.

Type: System.Type()

The types of the method's parameters.

Return Value

Type: System.Reflection.MethodInfo

The named method on an array class.

Exception Condition

arrayClass is not an array.


arrayClass or methodName is null.

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. For example, you might define a type and want to define a method that takes an array of the type as a parameter. In order to access the elements of the array, you will need to call methods of the Array class.

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.
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.Call, myMethodInfo)
' Complete the creation of type.

.NET Framework
Available since 1.1
Available since 2.0
Return to top