反射__获取delegate的信息

参考网址:http://stackoverflow.com/questions/429552/can-i-get-the-signature-of-a-c-sharp-delegate-by-its-type

 

1、我的测试代码:

namespace RefTest01
{
    [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    public delegate void D_Test01(int _i);

    // ***

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {/*
            if (FfnTest01 == null)
                MessageBox.Show("FfnTest01 == null");
            else
                FfnTest01(3);
          //*/

            Type delegateType = typeof(D_Test01);
            MethodInfo method = delegateType.GetMethod("Invoke");
            Console.WriteLine(method.ReturnType.Name + " (ret)");
            foreach (ParameterInfo param in method.GetParameters())
            {
                Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
            }
        }
    }
}

  打印信息:

Void (ret)
Int32 _i

 

2、

3、

 

posted @ 2016-06-02 16:04  csskill  阅读(275)  评论(0编辑  收藏  举报