Type.GetMethod メソッド (String, BindingFlags)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim returnValue As MethodInfo returnValue = instance.GetMethod(name, bindingAttr)
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
指定した要件と一致するメソッドが存在する場合は、そのメソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


次の BindingFlags フィルタ フラグは、検索対象に含めるメソッドを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないメソッド (つまり、プライベート メンバやプロテクト メンバ) を含めるための BindingFlags.NonPublic を指定します。
-
階層構造の上位にある public 静的メンバおよび protected 静的メンバを検索対象に含めるには、BindingFlags.FlattenHierarchy を指定します。継承クラスの private 静的メンバは含まれません。
次の BindingFlags 修飾フラグは、検索方法を変更するために使用できます。
詳細については、「System.Reflection.BindingFlags」を参照してください。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

指定したバインディング フラグに一致するメソッドを取得し、そのシグネチャを表示する例を次に示します。
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Class [MyClass] Public Sub MyMethod() End Sub 'MyMethod End Class '[MyClass] Public Class Type_GetMethod Public Shared Sub Main() Try ' Get the type of MyClass. Dim myType As Type = GetType([MyClass]) ' Get the method information for MyClass. Dim myMethodInfo As MethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public Or BindingFlags.Instance) ' Display the method information. Console.WriteLine(ControlChars.Cr + "The signature of MyMethod is: {0}", myMethodInfo.ToString()) Catch e As Exception Console.WriteLine("Exception: {0}", e.Message.ToString()) End Try End Sub 'Main End Class 'Type_GetMethod
using System; using System.Reflection; class MyClass { public void MyMethod() { } } public class Type_GetMethod { public static void Main() { try { // Get the type of MyClass. Type myType = typeof(MyClass); // Get the method information for MyClass. MethodInfo myMethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public|BindingFlags.Instance ); // Display the method information. Console.WriteLine("\nThe signature of MyMethod is: {0}", myMethodInfo.ToString()); } catch(Exception e) { Console.WriteLine("Exception: {0}", e.Message); } } }
using namespace System; using namespace System::Reflection; ref class MyClass { public: void MyMethod(){} }; int main() { try { // Get the type of MyClass. Type^ myType = MyClass::typeid; // Get the method information for MyClass. MethodInfo^ myMethodInfo = myType->GetMethod( "MyMethod", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) ); // Display the method information. Console::WriteLine( "\nThe signature of MyMethod is: {0}", myMethodInfo ); } catch ( Exception^ e ) { Console::WriteLine( "Exception: {0}", e->Message ); } }
import System.*; import System.Reflection.*; class MyClass { public void MyMethod() { } //MyMethod } //MyClass public class Type_GetMethod { public static void main(String[] args) { try { // Get the type of MyClass. Type myType = MyClass.class.ToType(); // Get the method information for MyClass. MethodInfo myMethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public | BindingFlags.Instance); // Display the method information. Console.WriteLine("\nThe signature of MyMethod is: {0}", myMethodInfo.ToString()); } catch (System.Exception e) { Console.WriteLine("Exception: {0}", e.get_Message()); } } //main } //Type_GetMethod


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetMethod メソッド (String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetMethod ( _ name As String, _ bindingAttr As BindingFlags, _ binder As Binder, _ callConvention As CallingConventions, _ types As Type(), _ modifiers As ParameterModifier() _ ) As MethodInfo
Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim binder As Binder Dim callConvention As CallingConventions Dim types As Type() Dim modifiers As ParameterModifier() Dim returnValue As MethodInfo returnValue = instance.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers)
public MethodInfo GetMethod ( string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers )
public: virtual MethodInfo^ GetMethod ( String^ name, BindingFlags bindingAttr, Binder^ binder, CallingConventions callConvention, array<Type^>^ types, array<ParameterModifier>^ modifiers ) sealed
public final MethodInfo GetMethod ( String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers )
public final function GetMethod ( name : String, bindingAttr : BindingFlags, binder : Binder, callConvention : CallingConventions, types : Type[], modifiers : ParameterModifier[] ) : MethodInfo
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
- binder
一連のプロパティを定義し、バインディングを有効にする Binder オブジェクト。バインディングには、オーバーロードされたメソッドの選択、引数の型の強制変換、リフレクションによるメンバの呼び出しなどが含まれます。
または
DefaultBinder を使用する場合は null 参照 (Visual Basic では Nothing)。
- callConvention
引数の順序とレイアウト、戻り値を渡す方法、引数を格納するレジスタ、スタックのクリーンアップの方法に関する一連の規則を指定する CallingConventions オブジェクト。
- types
取得するメソッドのパラメータの数、順序、および型を表す Type オブジェクトの配列。
または
パラメータをとらないメソッドを取得するための Type オブジェクトの空の配列 (EmptyTypes フィールドで指定)。
指定した要件と一致するメソッドが存在する場合は、そのメソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
型に対するリフレクション時に GetXXX メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
次の BindingFlags フィルタ フラグは、検索対象に含めるメソッドを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないメソッド (つまり、プライベート メンバやプロテクト メンバ) を含めるための BindingFlags.NonPublic を指定します。
-
階層構造の上位にある public 静的メンバおよび protected 静的メンバを検索対象に含めるには、BindingFlags.FlattenHierarchy を指定します。継承クラスの private 静的メンバは含まれません。
次の BindingFlags 修飾フラグは、検索方法を変更するために使用できます。
詳細については、「System.Reflection.BindingFlags」を参照してください。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

クラス MyClass の MyFunc という名前のメソッドに関する情報を表示する例を次に示します。
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class [MyClass] Public i As Integer = 10 Public j As Integer = 2 Public Function MyFunc(ByVal i As Integer, ByVal j As Integer) As Integer Dim k As Integer k = i * 10 - j Return k End Function 'MyFunc End Class '[MyClass] Public Class Type_GetMethod Public Shared Sub Main() Try ' Get the type of MyClass. Dim myType As Type = GetType([MyClass]) ' Get information for MyFunc(int, int). Dim myMemberInfo As MemberInfo = myType.GetMethod("MyFunc", BindingFlags.Public Or BindingFlags.Instance, Nothing, CallingConventions.Any, New Type() {GetType(Integer), GetType(Integer)}, Nothing) Console.WriteLine(ControlChars.NewLine + "Displaying method MyFunc: " + ControlChars.NewLine) ' Display the method information. Console.WriteLine("{0}", myMemberInfo) Catch e As Exception Console.WriteLine("Exception : {0}", e.Message.ToString()) End Try End Sub 'Main ' End Class 'Type_GetMethod
using System; using System.Reflection; public class MyClass { public int i = 10; public int j = 2; public int MyFunc(int i , int j) { int k; k = i * 10 - j; return k; } } public class Type_GetMethod { public static void Main() { try { // Get the type of MyClass. Type myType = typeof(MyClass); // Get the method information for MyFunc(int, int). MemberInfo myMemberInfo = myType.GetMethod("MyFunc", BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, new Type[] {typeof(int),typeof(int)}, null); Console.WriteLine("\nDisplaying information for MyFunc: \n"); // Display the method information. Console.WriteLine("{0}", myMemberInfo); } catch(Exception e) { Console.WriteLine("Exception : {0}", e.Message); } } }
using namespace System; using namespace System::Reflection; public ref class MyClass { public: int i; int j; int MyFunc( int i, int j ) { int k; k = i * 10 - j; return k; } }; int main() { try { // Get the type of MyClass. Type^ myType = MyClass::typeid; // Get the method information for MyFunc(int, int). array<Type^>^temp0 = {int::typeid,int::typeid}; MemberInfo^ myMemberInfo = myType->GetMethod( "MyFunc", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance), nullptr, CallingConventions::Any, temp0, nullptr ); Console::WriteLine( "\nDisplaying information for MyFunc: \n" ); // Display the method information. Console::WriteLine( "{0}", myMemberInfo ); } catch ( Exception^ e ) { Console::WriteLine( "Exception : {0}", e->Message ); } }
import System.*; import System.Reflection.*; public class MyClass { public int i = 10; public int j = 2; public int MyFunc(int i, int j) { int k; k = i * 10 - j; return k; } //MyFunc } //MyClass public class Type_GetMethod { public static void main(String[] args) { try { // Get the type of MyClass. Type myType = MyClass.class.ToType(); // Get the method information for MyFunc(int, int). MemberInfo myMemberInfo = myType.GetMethod("MyFunc", BindingFlags.Public | BindingFlags.Instance, null , CallingConventions.Any, new Type[] { int.class.ToType(), int.class.ToType() }, null); Console.WriteLine("\nDisplaying information for MyFunc: \n"); // Display the method information. Console.WriteLine("{0}", myMemberInfo); } catch (System.Exception e) { Console.WriteLine("Exception : {0}", e.get_Message()); } } //main } //Type_GetMethod


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetMethod メソッド (String, BindingFlags, Binder, Type[], ParameterModifier[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetMethod ( _ name As String, _ bindingAttr As BindingFlags, _ binder As Binder, _ types As Type(), _ modifiers As ParameterModifier() _ ) As MethodInfo
Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim binder As Binder Dim types As Type() Dim modifiers As ParameterModifier() Dim returnValue As MethodInfo returnValue = instance.GetMethod(name, bindingAttr, binder, types, modifiers)
public MethodInfo GetMethod ( string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers )
public: virtual MethodInfo^ GetMethod ( String^ name, BindingFlags bindingAttr, Binder^ binder, array<Type^>^ types, array<ParameterModifier>^ modifiers ) sealed
public final MethodInfo GetMethod ( String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers )
public final function GetMethod ( name : String, bindingAttr : BindingFlags, binder : Binder, types : Type[], modifiers : ParameterModifier[] ) : MethodInfo
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
- binder
一連のプロパティを定義し、バインディングを有効にする Binder オブジェクト。バインディングには、オーバーロードされたメソッドの選択、引数の型の強制変換、リフレクションによるメンバの呼び出しなどが含まれます。
または
DefaultBinder を使用する場合は null 参照 (Visual Basic では Nothing)。
- types
取得するメソッドのパラメータの数、順序、および型を表す Type オブジェクトの配列。
または
パラメータをとらないメソッドを取得するための Type オブジェクトの空の配列 (EmptyTypes フィールドで指定)。
指定した要件と一致するメソッドが存在する場合は、そのメソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
次の BindingFlags フィルタ フラグは、検索対象に含めるメソッドを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないメソッド (つまり、プライベート メンバやプロテクト メンバ) を含めるための BindingFlags.NonPublic を指定します。
-
階層構造の上位にある public 静的メンバおよび protected 静的メンバを検索対象に含めるには、BindingFlags.FlattenHierarchy を指定します。継承クラスの private 静的メンバは含まれません。
次の BindingFlags 修飾フラグは、検索方法を変更するために使用できます。
詳細については、「System.Reflection.BindingFlags」を参照してください。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

メソッド情報を取得し、シグネチャと宣言型を表示する例を次に示します。
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class [MyClass] Public i As Integer = 10 Public k As String = "My Field" Public Overloads Function MyMethod(ByVal i As Integer) As Integer Me.i = i Return i End Function 'MyMethod Public Overloads Function MyMethod(ByVal k As String) As String Me.k = k Return k End Function 'MyMethod End Class '[MyClass] Public Class Type_GetMethod Public Shared Sub Main() Try ' Get the type of MyClass. Dim myType As Type = GetType([MyClass]) ' Get the attributes and metadata of MyMethod. Dim myMethodInfo As MethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public Or BindingFlags.Instance, Nothing, New Type() {GetType(Integer)}, Nothing) Console.WriteLine(ControlChars.Cr + "Declaring type of the method {0} is : " + " {1}", myMethodInfo, myMethodInfo.DeclaringType.ToString()) ' Get the attributes and metadata of MyMethod. Dim myMethodInfo1 As MethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public Or BindingFlags.Instance, Nothing, New Type() {GetType(String)}, Nothing) Console.WriteLine(ControlChars.Cr + "Declaring type of the method {0} is : " + " {1}", myMethodInfo1, myMethodInfo1.DeclaringType.ToString()) Catch e As Exception Console.WriteLine("Exception: {0}", e.Message.ToString()) End Try End Sub 'Main End Class 'Type_GetMethod
using System; using System.Reflection; public class MyClass { public int i = 10; public string k = "My Field"; public int MyMethod(int i) { this.i = i; return i; } public string MyMethod(string k) { this.k = k; return k; } } public class Type_GetMethod { public static void Main() { try { // Get the type of MyClass. Type myType = typeof(MyClass); // Get the attributes and metadata of MyMethod. MethodInfo myMethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public | BindingFlags.Instance, null , new Type[] {typeof(int)}, null); Console.WriteLine("\n Declaring type of the method {0} is: \n {1}" , myMethodInfo, myMethodInfo.DeclaringType); // Get the attributes and metadata of MyMethod. MethodInfo myMethodInfo1 = myType.GetMethod("MyMethod", BindingFlags.Public | BindingFlags.Instance, null , new Type[] {typeof(string)}, null); Console.WriteLine("\n Declaring type of the method {0} is: \n {1}" , myMethodInfo1, myMethodInfo1.DeclaringType); } catch(Exception e) { Console.WriteLine("Exception: {0}", e.Message); } } }
using namespace System; using namespace System::Reflection; public ref class MyClass { public: int i; String^ k; int MyMethod( int i ) { this->i = i; return i; } String^ MyMethod( String^ k ) { this->k = k; return k; } }; int main() { try { // Get the type of MyClass. Type^ myType = MyClass::typeid; // Get the attributes and metadata of MyMethod. array<Type^>^temp0 = {int::typeid}; MethodInfo^ myMethodInfo = myType->GetMethod( "MyMethod", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance), nullptr, temp0, nullptr ); Console::WriteLine( "\n Declaring type of the method {0} is: \n {1}", myMethodInfo, myMethodInfo->DeclaringType ); // Get the attributes and metadata of MyMethod. array<Type^>^temp1 = {String::typeid}; MethodInfo^ myMethodInfo1 = myType->GetMethod( "MyMethod", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance), nullptr, temp1, nullptr ); Console::WriteLine( "\n Declaring type of the method {0} is: \n {1}", myMethodInfo1, myMethodInfo1->DeclaringType ); } catch ( Exception^ e ) { Console::WriteLine( "Exception: {0}", e->Message ); } }
import System.*; import System.Reflection.*; public class MyClass { public int i = 10; public String k = "My Field"; public int MyMethod(int i) { this.i = i; return i; } //MyMethod public String MyMethod(String k) { this.k = k; return k; } //MyMethod } //MyClass public class Type_GetMethod { public static void main(String[] args) { try { // Get the type of MyClass. Type myType = MyClass.class.ToType(); // Get the attributes and metadata of MyMethod. MethodInfo myMethodInfo = myType.GetMethod("MyMethod", BindingFlags.Public | BindingFlags.Instance, null , new Type[] { int.class.ToType() }, null); Console.WriteLine("\n Declaring type of the method {0} is: \n {1}" , myMethodInfo, myMethodInfo.get_DeclaringType()); // Get the attributes and metadata of MyMethod. MethodInfo myMethodInfo1 = myType.GetMethod("MyMethod", BindingFlags.Public | BindingFlags.Instance, null , new Type[] { String.class.ToType() }, null); Console.WriteLine("\n Declaring type of the method {0} is: \n {1}" , myMethodInfo1, myMethodInfo1.get_DeclaringType()); } catch (System.Exception e) { Console.WriteLine("Exception: {0}", e.get_Message()); } } //main } //Type_GetMethod


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetMethod メソッド (String, Type[])
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim name As String Dim types As Type() Dim returnValue As MethodInfo returnValue = instance.GetMethod(name, types)
- types
取得するメソッドのパラメータの数、順序、および型を表す Type オブジェクトの配列。
または
パラメータをとらないメソッドを取得するための Type オブジェクトの空の配列 (EmptyTypes フィールドで指定)。
指定した引数型と一致するパラメータが設定されたパブリック メソッドが存在する場合は、そのパブリック メソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス メソッドが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

オーバーロードされたメソッドを持つクラスの例を次に示します。MyClass1 に対応する Type オブジェクトを取得し、GetMethod を呼び出します。このメソッドの呼び出しにより、パラメータが型の配列で指定した引数と一致するメソッドが返されます。
Imports System Imports System.Reflection Public Class MyClass1 Public Overloads Sub MyMethod(ByVal i As Integer) End Sub Public Overloads Sub MyMethod(ByVal i As Integer, ByVal j As Integer) End Sub End Class Public Class TestMyClass Public Shared Sub Main() Try ' Get a Type object corresponding to MyClass1. Dim myClassType As Type = GetType(MyClass1) ' Create a Type array. Dim typeArray(0) As Type typeArray.SetValue(GetType(Integer), 0) ' Find the method matching the specified argument types. Dim myMethodInfo As MethodInfo = myClassType.GetMethod("MyMethod", typeArray) Console.WriteLine("The name of the Method :" & myMethodInfo.ToString()) Catch e As Exception Console.WriteLine(e.Message) End Try End Sub End Class
using System; using System.Reflection; public class MyClass1 { public void MyMethod(int i) { } public void MyMethod(int i,int j) { } } public class TestMyClass { public static void Main() { try { // Get a Type object corresponding to MyClass1. Type myClassType = typeof(MyClass1); // Create a Type array. Type[] typeArray =new Type[1]; typeArray.SetValue(typeof(int),0); // Find the method matching the specified argument types. MethodInfo myMethodInfo = myClassType.GetMethod("MyMethod", typeArray); Console.WriteLine("The name of the method :" + myMethodInfo); } catch(Exception e) { Console.WriteLine(e.Message); } } }
using namespace System; using namespace System::Reflection; public ref class MyClass1 { public: void MyMethod( int ){} void MyMethod( int, int ){} }; int main() { try { // Get a Type object corresponding to MyClass1. Type^ myClassType = MyClass1::typeid; // Create a Type array. array<Type^>^typeArray = gcnew array<Type^>(1); typeArray->SetValue( int::typeid, 0 ); // Find the method matching the specified argument types. MethodInfo^ myMethodInfo = myClassType->GetMethod( "MyMethod", typeArray ); Console::WriteLine( "The name of the method : {0}", myMethodInfo ); } catch ( Exception^ e ) { Console::WriteLine( e->Message ); } }
import System.*; import System.Reflection.*; public class MyClass1 { public void MyMethod(int i) { } //MyMethod public void MyMethod(int i, int j) { } //MyMethod } //MyClass1 public class TestMyClass { public static void main(String[] args) { try { // Get a Type object corresponding to MyClass1. Type myClassType = MyClass1.class.ToType(); // Create a Type array. Type typeArray[] = new Type[1]; typeArray.SetValue(int.class.ToType(), 0); // Find the method matching the specified argument types. MethodInfo myMethodInfo = myClassType.GetMethod("MyMethod", typeArray); Console.WriteLine("The name of the method :" + myMethodInfo); } catch (System.Exception e) { Console.WriteLine(e.get_Message()); } } //main } //TestMyClass


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetMethod メソッド (String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim name As String Dim returnValue As MethodInfo returnValue = instance.GetMethod(name)
戻り値
指定した名前のパブリック メソッドが存在する場合は、そのパブリック メソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス メソッドが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

MyClass で MyFunction のパラメータを取得し、それらの位置とデータ型を表示する例を次に示します。
Imports System Imports System.Reflection Imports System.Security Imports Microsoft.VisualBasic Class [MyClass] Public myInt As Integer = 0 Public myString As String = Nothing Public Sub New() End Sub 'New Public Sub Myfunction(ByVal i As Integer) End Sub 'Myfunction End Class '[MyClass] Class Type_GetMethod Public Shared Sub Main() Try Dim MyObject As New [MyClass]() Dim myMethodInfo As MethodInfo ' Get the type of MyClass. Dim myType As Type = MyObject.GetType() ' Get the method information for MyFunction. myMethodInfo = myType.GetMethod("Myfunction") ' Get the parameters for Myfunction. Dim myParameters As ParameterInfo() = myMethodInfo.GetParameters() Console.WriteLine(ControlChars.Cr + "The parameters of the method Myfunction of class MyClass are:" + ControlChars.Cr) ' Display the position and type of the parameters. Dim i As Integer For i = 0 To myParameters.Length - 1 Console.WriteLine("The data type of parameter {0} is {1}.", myParameters(i).Position + 1, myParameters(i).ParameterType) Next i Catch e As SecurityException Console.WriteLine(("SecurityException: " + e.Message.ToString())) Catch e As Exception Console.WriteLine(("Exception: " + e.Message.ToString())) End Try End Sub 'Main End Class 'Type_GetMethod
using System; using System.Reflection; using System.Security; class MyClass { public int myInt = 0; public string myString = null; public MyClass() { } public void Myfunction(int i) { } } class Type_GetMethod { public static void Main() { try { MyClass MyObject = new MyClass(); MethodInfo myMethodInfo; // Get the type of MyClass. Type myType = MyObject.GetType(); // Get the method information for MyFunction. myMethodInfo = myType.GetMethod("Myfunction"); // Get the parameters for Myfunction. ParameterInfo[] myParameters = myMethodInfo.GetParameters(); Console.WriteLine( "\nThe parameters of the method Myfunction of class MyClass are :\n"); // Display the position and type of the parameters. for(int i = 0; i < myParameters.Length; i++) Console.WriteLine("The data type of parameter {0} is {1}." , myParameters[i].Position + 1, myParameters[i].ParameterType); } catch (SecurityException e) { Console.WriteLine("SecurityException: " + e.Message ); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message ); } } }
using namespace System; using namespace System::Reflection; using namespace System::Security; ref class MyClass { public: int * myInt; String^ myString; MyClass(){} void Myfunction( int i ) { myString = i.ToString(); } }; int main() { try { MyClass^ MyObject = gcnew MyClass; MethodInfo^ myMethodInfo; // Get the type of MyClass. Type^ myType = MyObject->GetType(); // Get the method information for MyFunction. myMethodInfo = myType->GetMethod( "Myfunction" ); // Get the parameters for Myfunction. array<ParameterInfo^>^myParameters = myMethodInfo->GetParameters(); Console::WriteLine( "\nThe parameters of the method Myfunction of class MyClass are :\n" ); // Display the position and type of the parameters. for ( int i = 0; i < myParameters->Length; i++ ) Console::WriteLine( "The data type of parameter {0} is {1}.", myParameters[ i ]->Position + 1, myParameters[ i ]->ParameterType ); } catch ( SecurityException^ e ) { Console::WriteLine( "SecurityException: {0}", e->Message ); } catch ( Exception^ e ) { Console::WriteLine( "Exception: {0}", e->Message ); } }
import System.*; import System.Reflection.*; import System.Security.*; class MyClass { public int myInt = 0; public String myString = null; public MyClass() { } //MyClass public void Myfunction(int i) { } //Myfunction } //MyClass class Type_GetMethod { public static void main(String[] args) { try { MyClass myObject = new MyClass(); MethodInfo myMethodInfo; // Get the type of MyClass. Type myType = myObject.GetType(); // Get the method information for MyFunction. myMethodInfo = myType.GetMethod("Myfunction"); // Get the parameters for Myfunction. ParameterInfo myParameters[] = myMethodInfo.GetParameters(); Console.WriteLine("\nThe parameters of the method Myfunction of" + " class MyClass are :\n"); // Display the position and type of the parameters. for (int i = 0; i < myParameters.length; i++) { Console.WriteLine("The data type of parameter {0} is {1}." , (Int32)(myParameters[i].get_Position() + 1), myParameters[i].get_ParameterType()); } } catch (SecurityException e) { Console.WriteLine("SecurityException: " + e.get_Message()); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.get_Message()); } } //main } //Type_GetMethod


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetMethod メソッド

名前 | 説明 |
---|---|
Type.GetMethod (String) | 指定した名前のパブリック メソッドを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethod (String, BindingFlags) | 指定したバインディング制約を使用して、指定したメソッドを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethod (String, Type[]) | 指定したパブリック メソッドのうち、指定した引数型と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethod (String, Type[], ParameterModifier[]) | 指定したパブリック メソッドのうち、指定した引数の型および修飾子と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethod (String, BindingFlags, Binder, Type[], ParameterModifier[]) | 指定したバインディング制約を使用して、指定したメソッドのうち、指定した引数の型および修飾子と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethod (String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) | 指定したバインディング制約および指定した呼び出し規約を使用して、指定したメソッドのうち、指定した引数の型および修飾子と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |

Type.GetMethod メソッド (String, Type[], ParameterModifier[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetMethod ( _ name As String, _ types As Type(), _ modifiers As ParameterModifier() _ ) As MethodInfo
Dim instance As Type Dim name As String Dim types As Type() Dim modifiers As ParameterModifier() Dim returnValue As MethodInfo returnValue = instance.GetMethod(name, types, modifiers)
public: virtual MethodInfo^ GetMethod ( String^ name, array<Type^>^ types, array<ParameterModifier>^ modifiers ) sealed
public final function GetMethod ( name : String, types : Type[], modifiers : ParameterModifier[] ) : MethodInfo
- types
取得するメソッドのパラメータの数、順序、および型を表す Type オブジェクトの配列。
または
パラメータをとらないメソッドを取得するための Type オブジェクトの空の配列 (EmptyTypes フィールドで指定)。
指定した要件と一致するパブリック メソッドが存在する場合は、そのパブリック メソッドを表す MethodInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性のために使用されます。
name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス メソッドが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_Type.GetMethod メソッド

名前 | 説明 |
---|---|
_Type.GetMethod (String) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetMethod (String, BindingFlags) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetMethod (String, Type[]) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetMethod (String, Type[], ParameterModifier[]) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetMethod (String, BindingFlags, Binder, Type[], ParameterModifier[]) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetMethod (String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) | COM オブジェクトに、Type.GetMethod メソッドへのバージョンに依存しないアクセスが用意されています。 |

Weblioに収録されているすべての辞書からType.GetMethodを検索する場合は、下記のリンクをクリックしてください。

- Type.GetMethodのページへのリンク