ModuleBuilder.GetArrayMethod メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ModuleBuilder.GetArrayMethod メソッドの意味・解説 

ModuleBuilder.GetArrayMethod メソッド

配列クラスの名前付きメソッドを返します。

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function GetArrayMethod ( _
    arrayClass As Type, _
    methodName As String, _
    callingConvention As CallingConventions, _
    returnType As Type, _
    parameterTypes As Type() _
) As MethodInfo
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 MethodInfo

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

パラメータ

arrayClass

配列クラス。

methodName

配列クラスのメソッドの名前。

callingConvention

メソッドの呼び出し規約。

returnType

メソッドの戻り値の型。

parameterTypes

メソッドのパラメータの型。

戻り値
配列クラスの名前付きメソッド。

例外例外
例外の種類条件

ArgumentException

arrayClass が配列ではありません。

ArgumentNullException

arrayClass または methodName が null 参照 (Visual Basic では Nothing) です。

解説解説

GetArrayMethod は、定義が完了していない型の配列があり、Array に定義されているメソッドにアクセスするときに役立ちます。たとえば、型を定義して、その型の配列をパラメータとするメソッドを定義できます。配列の要素にアクセスするには、Array クラスのメソッドを呼び出す必要があります。

使用例使用例

次のコード例は、GetArrayMethod を使用して、配列値を返すメソッドに対応する MethodInfo を取得する方法を示しています。

' 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();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ModuleBuilder クラス
ModuleBuilder メンバ
System.Reflection.Emit 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からModuleBuilder.GetArrayMethod メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からModuleBuilder.GetArrayMethod メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からModuleBuilder.GetArrayMethod メソッド を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

ModuleBuilder.GetArrayMethod メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ModuleBuilder.GetArrayMethod メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS