c# Event移除所有绑定,注销事件绑定

    public delegate int MasterEventHandler(object dat);
    public event MasterEventHandler Event;


    /// 
    /// 
    /// 
    public void CLearAllEvent()
    {
        if (Event == null) return;
        Delegate[] dels = Event.GetInvocationList();
        foreach (Delegate del in dels)
        {
            object delObj = del.GetType().GetProperty("Method").GetValue(del, null);
            string funcName = (string)delObj.GetType().GetProperty("Name").GetValue(delObj, null);方法名
            Console.WriteLine(funcName);
            Event -= del as MasterEventHandler;
        }
    }

你可能感兴趣的:(c#)