将虚拟方法注册为事件处理程序而不是注册委托给虚拟方法的私有方法是否有任何问题?我更喜欢选项 1(这似乎可行),但我想确保它以后不会咬我。
选项1
public class Controller1
{
public Controller1(EventNotifier eventNotifier)
{
eventNotifier.ImportantEvent += OnEventNotifierImportantEvent;
}
protected virtual void OnEventNotifierImportantEvent(object sender, EventArgs e)
{
}
}
选项 2
public class Controller2
{
public Controller2(EventNotifier eventNotifier)
{
eventNotifier.ImportantEvent += eventNotifier_OnImportantEvent;
}
private void eventNotifier_OnImportantEvent(object sender, EventArgs eventArgs)
{
OnEventNotifierImportantEvent(sender, eventArgs);
}
protected virtual void OnEventNotifierImportantEvent(object sender, EventArgs e)
{
}
}