继承事件处理程序

Ale*_*der 0 .net c# events inheritance

我试图为不同的报告写抽象类.

我有一个方法

protected Tuple<byte[], string, string> RenderReport()
Run Code Online (Sandbox Code Playgroud)

有这样的台词

var localReport = new LocalReport { ReportPath = _reportLocalFullName };
...
localReport.SubreportProcessing += localReport_SubreportProcessing;
Run Code Online (Sandbox Code Playgroud)

派生类必须在localReport_SubreportProcessing中编写自己的代码.

我不知道如何在这里继承.有人可以帮忙吗?

Mar*_*ell 5

而不是有一个方法:

private void localReport_SubreportProcessing(...) {...}
Run Code Online (Sandbox Code Playgroud)

考虑一下:

protected virtual void OnSubreportProcessing(...) {...}
Run Code Online (Sandbox Code Playgroud)

现在你的子类可以简单地使用:

protected override void OnSubreportProcessing(...) {...}
Run Code Online (Sandbox Code Playgroud)