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 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

適用対象

こちらもご覧ください