private delegate int DEL_TEST_EventHandler(int m, int n);private event DEL_TEST_EventHandler DelTestEventHandler;/// <summary>/// 移除所有的事件绑定/// </summary>/// <param name="clearEvent"></param>private void clear_event(DEL_TEST_EventHandler clearEvent){Delegate[] dels = DelTestEventHandler.GetInvocationList();foreach (Delegate d in dels){/*--------------------------------------*///得到方法名object delObj = d.GetType().GetProperty("Method").GetValue(d, null);string funcName = (string)delObj.GetType().GetProperty("Name").GetValue(delObj, null);Debug.Print(funcName);/*--------------------------------------*/DelTestEventHandler -= d as DEL_TEST_EventHandler;}}//测试主函数private void test(){DelTestEventHandler += add;DelTestEventHandler += sub;DelTestEventHandler += add;DelTestEventHandler += sub;clear_event(DelTestEventHandler);}private int add(int m, int n){return m + n;}private static int sub(int m, int n){return m - n;}
C# 移除所有的事件绑定
最新推荐文章于 2020-11-03 16:37:31 发布