C#.NET 删除事件所有订阅
C# 全选
var instance = FastReport.Utils.Config.DesignerSettings; //实例
var eventName = "CustomSaveDialog"; //需要删除所有订阅的事件名称
//删除旧的事件,避免重复添加事件
FieldInfo fieldInfo = instance.GetType().GetField(eventName, BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo != null)
{
var eventDelegate = fieldInfo.GetValue(instance) as Delegate;
if (eventDelegate != null)
{
var handleList = eventDelegate.GetInvocationList();
foreach (Delegate handler in handleList)
{
instance.CustomSaveDialog -= (OpenSaveDialogEventHandler)handler; //删除订阅
}
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网