MethodBase.GetParameters メソッド

定義

派生クラスによってオーバーライドされた場合、指定したメソッドまたはコンストラクターのパラメーターを取得します。

public:
 abstract cli::array <System::Reflection::ParameterInfo ^> ^ GetParameters();
public abstract System.Reflection.ParameterInfo[] GetParameters ();
abstract member GetParameters : unit -> System.Reflection.ParameterInfo[]
Public MustOverride Function GetParameters () As ParameterInfo()

戻り値

この MethodBase インスタンスでリフレクションされたメソッド (またはコンストラクター) のシグネチャと一致する情報を格納している ParameterInfo 型の配列。

実装

次の例では、 メソッドを GetParameters 使用して、デリゲートの メソッドの Invoke パラメーターを取得します。

この例では、 という名前 MyDelegate のデリゲートと 型の という名前 ev のイベントを定義します MyDelegate。 メソッドの Main コードは、イベントのデリゲート型を取得し、デリゲート型のメソッドを取得 Invoke し、パラメーターを取得して表示することで、イベント シグネチャを検出します。

// The following example uses instances of classes in
// the System::Reflection namespace to discover an event argument type.
using namespace System;
using namespace System::Reflection;

public delegate void MyDelegate( int i );
public ref class MainClass
{
public:
   event MyDelegate^ ev;
};

int main()
{
   Type^ delegateType = MainClass::typeid->GetEvent( "ev" )->EventHandlerType;
   MethodInfo^ invoke = delegateType->GetMethod( "Invoke" );
   array<ParameterInfo^>^pars = invoke->GetParameters();
   System::Collections::IEnumerator^ myEnum = pars->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      ParameterInfo^ p = safe_cast<ParameterInfo^>(myEnum->Current);
      Console::WriteLine( p->ParameterType );
   }
}
// The example displays the following output:
//       System.Int32
// The following example uses instances of classes in
// the System.Reflection namespace to discover an event argument type.
using System;
using System.Reflection;

public delegate void MyDelegate(int i);
public class MainClass
{
    public event MyDelegate ev;

    public static void Main()
    {
        Type delegateType = typeof(MainClass).GetEvent("ev").EventHandlerType;
        MethodInfo invoke = delegateType.GetMethod("Invoke");
        ParameterInfo[] pars = invoke.GetParameters();
        foreach (ParameterInfo p in pars)
        {
            Console.WriteLine(p.ParameterType);
        }
    }
}
// The example displays the following output:
//       System.Int32
Imports System.Reflection

Public Delegate Sub MyDelegate(ByVal i As Integer)

Public Class MainClass
    Public Event ev As MyDelegate

    Public Shared Sub Main()
        Dim delegateType As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
        Dim invoke As MethodInfo = delegateType.GetMethod("Invoke")
        Dim pars As ParameterInfo() = invoke.GetParameters()
        For Each p As ParameterInfo In pars
            Console.WriteLine(p.ParameterType)
        Next 
    End Sub 
End Class 
' The example displays the following output:
'     System.Int32

適用対象

こちらもご覧ください