Type.GetMethods メソッド ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Type.GetMethods メソッド ()」の関連用語

Type.GetMethods メソッド ()のお隣キーワード
検索ランキング

   

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



Type.GetMethods メソッド ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS