现在的位置: 首页 > 综合 > 正文

如何获取谁在委托

2013年11月08日 ⁄ 综合 ⁄ 共 1226字 ⁄ 字号 评论关闭

http://topic.csdn.net/u/20090915/14/3b383aad-a5b5-45d5-89c8-56d5898e297f.html?seed=1021591837&r=59815085#r_59815085

 

    private List<Control> GetMethodObject(string method)
        {
            List<Control> list = new List<Control>();
            PropertyInfo pi = typeof(Component).GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo fi in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static))
            {
              
                if (fi.FieldType.IsSubclassOf(typeof(Control)))
                {
                    Control ctl = fi.GetValue(this) as Control;
                    EventHandlerList ehl = pi.GetValue(ctl, null) as EventHandlerList;
                    object key = typeof(Control).GetField("EventClick", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                    Delegate del = ehl[key];
                    if (del != null)
                    {
                        foreach (Delegate de in del.GetInvocationList())
                        {
                            if (de.Method.Name == method)
                                list.Add(ctl);
                        }
                    }
                }
            }
            return list;
        }

抱歉!评论已关闭.