• 反射方法获取事件的委托链上的函数


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    
    
    namespace TestDev
    {
        class Program
        {
            static void Main(string[] args)
            {
            
                System.Windows.Forms.Button btn = new System.Windows.Forms.Button();
                btn.Click += new EventHandler(btn_Click);
                btn.Click += new EventHandler(btn_Click2);
                btn.Click += new EventHandler(btn_Click3);
                btn.MouseMove += btn_MouseMove;
                btn.MouseMove += btn_MouseMove2;
                
                PropertyInfo pi = btn.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
                EventHandlerList ehl = (EventHandlerList)pi.GetValue(btn, null);//EventClick
                FieldInfo fieldInfo = (typeof(System.Windows.Forms.Control)).GetField("EventMouseMove", BindingFlags.Static | BindingFlags.NonPublic);
                Delegate d = ehl[fieldInfo.GetValue(null)];
                foreach (Delegate del in d.GetInvocationList())
                    Console.WriteLine(del.Method.Name);
               
    
            }
    
            static void btn_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                throw new NotImplementedException();
            }
    
            static void btn_MouseMove2(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                throw new NotImplementedException();
            }
    
            static void btn_Click(object sender, EventArgs e)
            {
                Console.WriteLine("Click1");
            }
     
            static void btn_Click2(object sender, EventArgs e)
            {
                Console.WriteLine("Click2");
            }
     
            static void btn_Click3(object sender, EventArgs e)
            {
                Console.WriteLine("Click3");
            }
            
        }
    }
  • 相关阅读:
    mysql 批量kill locked 进程
    mysql大量locked的一个案例
    Nodejs微信开发使用wechat-api回复多条消息
    nodejs获取ASP.Net WebAPI(IIS Windows验证)
    Nodejs微信开发
    Luis创建与发布
    Bot Framework测试
    使用httpclient异步调用WebAPI接口
    sonarQube Github pull request扫描代码
    sonarQube6.1 升级至6.2
  • 原文地址:https://www.cnblogs.com/arxive/p/6932445.html
Copyright © 2020-2023  润新知