Type.GetMethodsとは? わかりやすく解説

Type.GetMethods メソッド ()

現在の Type のすべてのパブリック メソッドを返します。

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

Public Function GetMethods As
 MethodInfo()
Dim instance As Type
Dim returnValue As MethodInfo()

returnValue = instance.GetMethods
public MethodInfo[] GetMethods ()
public:
virtual array<MethodInfo^>^ GetMethods () sealed
public final MethodInfo[] GetMethods ()
public final function GetMethods () : MethodInfo[]

戻り値
現在の Type に対して定義されているすべてのパブリック メソッドを表す MethodInfo オブジェクトの配列。 または 現在の Type に対してパブリック メソッドが定義されていない場合は、MethodInfo 型の空の配列。

解説解説

この呼び出しによって返されるメソッドの配列には、コンストラクタは含まれません。コンストラクタのメソッドを取得するには、GetConstructors() への別の呼び出しを行ってください。

型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。

  1. 名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。

  2. リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。

  3. カスタム属性は、共通型システムの一部ではありません。

現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて MethodInfo オブジェクトを返します。

現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のメソッドを検索します。クラス制約がない場合は、Object のメソッドを検索します。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Type.GetMethods メソッド (BindingFlags)

派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、現在の Type に対して定義されているメソッドを検索します。

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

Public MustOverride Function
 GetMethods ( _
    bindingAttr As BindingFlags _
) As MethodInfo()
Dim instance As Type
Dim bindingAttr As BindingFlags
Dim returnValue As MethodInfo()

returnValue = instance.GetMethods(bindingAttr)
public abstract MethodInfo[] GetMethods (
    BindingFlags bindingAttr
)
public:
virtual array<MethodInfo^>^ GetMethods (
    BindingFlags bindingAttr
) abstract
public abstract MethodInfo[] GetMethods (
    BindingFlags bindingAttr
)
public abstract function GetMethods (
    bindingAttr : BindingFlags
) : MethodInfo[]

パラメータ

bindingAttr

検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。

または

null 参照 (Visual Basic では Nothing) を返す 0。

戻り値
現在の Type に対して定義されているメソッドのうち、指定したバインディング制約に一致するすべてのメソッドを表す MethodInfo オブジェクトの配列。 または 現在の Type に対してメソッドが定義されていないか、または定義されているメソッドの中にバインディング制約に一致するものが存在しない場合は、MethodInfo 型の空の配列。

解説解説

次の BindingFlags フィルタ フラグは、検索対象に含めるメソッドを定義するために使用できます。

次の 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
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
MethodInfo
BindingFlags
DefaultBinder
ReflectionPermission
GetMethod

Type.GetMethods メソッド


_Type.GetMethods メソッド

COM オブジェクトに、System.Type.GetMethods メソッドへのバージョンに依存しないアクセスが用意されています。
オーバーロードの一覧オーバーロードの一覧

名前 説明
_Type.GetMethods () COM オブジェクトに、Type.GetMethods メソッドへのバージョンに依存しないアクセスが用意されています。
_Type.GetMethods (BindingFlags) COM オブジェクトに、Type.GetMethods メソッドへのバージョンに依存しないアクセスが用意されています。
参照参照

関連項目

_Type インターフェイス
_Type メンバ
System.Runtime.InteropServices 名前空間



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「Type.GetMethods」の関連用語

Type.GetMethodsのお隣キーワード
検索ランキング

   

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



Type.GetMethodsのページの著作権

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

©2026 GRAS Group, Inc.RSS