通常我会去:
bgwExportGrid.RunWorkerCompleted += ReportManager.RunWorkerCompleted;
ReportManager 类是一个包含我要使用的事件处理程序的静态类。
public static class ReportManager
{
public static void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
...
}
}
现在,我创建了一个 BackgroundWorker,并希望附加 ReportManager 中定义的 RunWorkerCompleted 事件。但是 ReportManager 不能被引用,否则会发生循环引用,因此需要反射。
任何帮助将不胜感激。
我已经查看了以下内容,但还没有走得太远:
Assembly assem = Utils.GetAssembly("WinUI.Reporting.Common.dll");
Type reportManagerType = assem.GetModule("WinUI.Reporting.Common.dll").GetType("WinUI.Reporting.Common.ReportManager");
EventInfo evWorkerCompleted = reportManagerType.GetEvent("RunWorkerCompleted");
Type tDelegate = evWorkerCompleted.EventHandlerType;