net GetEvent GetParameters 通过反射获取事件的参数


// 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, string j);
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);
        }
        Console.Read();
    }
}
// The example displays the following output:
// system.int32
// system.string


作者:spike

分类: Net

创作时间:2023-06-25

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1