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

Dim instance As Type Dim returnValue As MethodInfo() returnValue = instance.GetMethods
現在の Type に対して定義されているすべてのパブリック メソッドを表す MethodInfo オブジェクトの配列。 または 現在の Type に対してパブリック メソッドが定義されていない場合は、MethodInfo 型の空の配列。

この呼び出しによって返されるメソッドの配列には、コンストラクタは含まれません。コンストラクタのメソッドを取得するには、GetConstructors() への別の呼び出しを行ってください。
型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
現在の 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.GetMethods メソッド (BindingFlags)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim bindingAttr As BindingFlags Dim returnValue As MethodInfo() returnValue = instance.GetMethods(bindingAttr)
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
現在の Type に対して定義されているメソッドのうち、指定したバインディング制約に一致するすべてのメソッドを表す MethodInfo オブジェクトの配列。 または 現在の Type に対してメソッドが定義されていないか、または定義されているメソッドの中にバインディング制約に一致するものが存在しない場合は、MethodInfo 型の空の配列。

次の 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 のメソッドを検索します。

2 つのパブリック メソッドと 1 つのプロテクト メソッドを持つクラスを作成し、MyTypeClass に対応する Type オブジェクトを作成し、パブリックおよび非パブリックのすべてのメソッドを取得して、それらの名前を表示する例を次に示します。
Imports System Imports System.Reflection Imports System.Reflection.Emit Imports Microsoft.VisualBasic ' Create a class having two public methods and one protected method. Public Class MyTypeClass Public Sub MyMethods() End Sub 'MyMethods Public Function MyMethods1() As Integer Return 3 End Function 'MyMethods1 Protected Function MyMethods2() As [String] Return "hello" End Function 'MyMethods2 End Class 'MyTypeClass Public Class TypeMain Public Shared Sub Main() Dim myType As Type = GetType(MyTypeClass) ' Get the public methods. Dim myArrayMethodInfo As MethodInfo() = myType.GetMethods((BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)) Console.WriteLine((ControlChars.Cr + "The number of public methods is " & myArrayMethodInfo.Length.ToString() & ".")) ' Display all the public methods. DisplayMethodInfo(myArrayMethodInfo) ' Get the nonpublic methods. Dim myArrayMethodInfo1 As MethodInfo() = myType.GetMethods((BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)) Console.WriteLine((ControlChars.Cr + "The number of protected methods is " & myArrayMethodInfo1.Length.ToString() & ".")) ' Display all the nonpublic methods. DisplayMethodInfo(myArrayMethodInfo1) End Sub 'Main Public Shared Sub DisplayMethodInfo(ByVal myArrayMethodInfo() As MethodInfo) ' Display information for all methods. Dim i As Integer For i = 0 To myArrayMethodInfo.Length - 1 Dim myMethodInfo As MethodInfo = CType(myArrayMethodInfo(i), MethodInfo) Console.WriteLine((ControlChars.Cr + "The name of the method is " & myMethodInfo.Name & ".")) Next i End Sub 'DisplayMethodInfo End Class 'TypeMain
using System; using System.Reflection; using System.Reflection.Emit; // Create a class having two public methods and one protected method. public class MyTypeClass { public void MyMethods() { } public int MyMethods1() { return 3; } protected String MyMethods2() { return "hello"; } } public class TypeMain { public static void Main() { Type myType =(typeof(MyTypeClass)); // Get the public methods. MethodInfo[] myArrayMethodInfo = myType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly); Console.WriteLine("\nThe number of public methods is {0}.", myArrayMethodInfo.Length); // Display all the methods. DisplayMethodInfo(myArrayMethodInfo); // Get the nonpublic methods. MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly); Console.WriteLine("\nThe number of protected methods is {0}.", myArrayMethodInfo1.Length); // Display information for all methods. DisplayMethodInfo(myArrayMethodInfo1); } public static void DisplayMethodInfo(MethodInfo[] myArrayMethodInfo) { // Display information for all methods. for(int i=0;i<myArrayMethodInfo.Length;i++) { MethodInfo myMethodInfo = (MethodInfo)myArrayMethodInfo[i]; Console.WriteLine("\nThe name of the method is {0}.", myMethodInfo.Name); } } }
using namespace System; using namespace System::Reflection; using namespace System::Reflection::Emit; // Create a class having two public methods and one protected method. public ref class MyTypeClass { public: void MyMethods(){} int MyMethods1() { return 3; } protected: String^ MyMethods2() { return "hello"; } }; void DisplayMethodInfo( array<MethodInfo^>^myArrayMethodInfo ) { // Display information for all methods. for ( int i = 0; i < myArrayMethodInfo->Length; i++ ) { MethodInfo^ myMethodInfo = dynamic_cast<MethodInfo^>(myArrayMethodInfo[ i ]); Console::WriteLine( "\nThe name of the method is {0}.", myMethodInfo->Name ); } } int main() { Type^ myType = MyTypeClass::typeid; // Get the public methods. array<MethodInfo^>^myArrayMethodInfo = myType->GetMethods( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance | BindingFlags::DeclaredOnly) ); Console::WriteLine( "\nThe number of public methods is {0}->", myArrayMethodInfo->Length ); // Display all the methods. DisplayMethodInfo( myArrayMethodInfo ); // Get the nonpublic methods. array<MethodInfo^>^myArrayMethodInfo1 = myType->GetMethods( static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::DeclaredOnly) ); Console::WriteLine( "\nThe number of protected methods is {0}->", myArrayMethodInfo1->Length ); // Display information for all methods. DisplayMethodInfo( myArrayMethodInfo1 ); }
import System.*; import System.Reflection.*; import System.Reflection.Emit.*; // Create a class having two public methods and one protected method. public class MyTypeClass { public void MyMethods() { } //MyMethods public int MyMethods1() { return 3; } //MyMethods1 protected String MyMethods2() { return "hello"; } //MyMethods2 } //MyTypeClass public class TypeMain { public static void main(String[] args) { Type myType = MyTypeClass.class.ToType(); // Get the public methods. MethodInfo myArrayMethodInfo[] = myType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); Console.WriteLine("\nThe number of public methods is {0}.", (Int32)(myArrayMethodInfo.length)); // Display all the methods. DisplayMethodInfo(myArrayMethodInfo); // Get the nonpublic methods. MethodInfo myArrayMethodInfo1[] = myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); Console.WriteLine("\nThe number of protected methods is {0}.", (Int32)(myArrayMethodInfo1.length)); // Display information for all methods. DisplayMethodInfo(myArrayMethodInfo1); } //main public static void DisplayMethodInfo(MethodInfo myArrayMethodInfo[]) { // Display information for all methods. for (int i = 0; i < myArrayMethodInfo.length; i++) { MethodInfo myMethodInfo = (MethodInfo)myArrayMethodInfo.get_Item(i); Console.WriteLine("\nThe name of the method is {0}.", myMethodInfo.get_Name()); } } //DisplayMethodInfo } //TypeMain


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.GetMethods メソッド

名前 | 説明 |
---|---|
Type.GetMethods () | 現在の Type のすべてのパブリック メソッドを返します。 .NET Compact Framework によってサポートされています。 |
Type.GetMethods (BindingFlags) | 派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、現在の Type に対して定義されているメソッドを検索します。 .NET Compact Framework によってサポートされています。 |

_Type.GetMethods メソッド
- Type.GetMethodsのページへのリンク