知道方法的MethodInfo,如何得到它的运行时的指针/委托还是叫别的什么
代码如下,最后一句能修改一下实现删除掉事件注册吗?
var frm = new Form1();
var method = frm.GetType().GetMethod("Form1_FormClosing", BindingFlags.Instance | BindingFlags.NonPublic);
frm.GetType().GetEvent("FormClosing").GetRemoveMethod().Invoke(frm, new object[] {method}); //exception: 类型“System.Reflection.RuntimeMethodInfo”的对象无法转换为类型“System.Windows.Forms.FormClosingEventHandler”
[解决办法]
这里有答案:
C#中利用反射清空事件列表