Get the parameters of the specified method or constructor in CSharp

Description

The following code shows how to get the parameters of the specified method or constructor.

Example


using System;/* ww  w .j  a v  a  2s .  c o m*/
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 code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type