When implementing events, you can specify the code for the add and remove event handler. However, events can be accessed in three ways:
MyEvent += Handler; // add accessor MyEvent -= Handler; // remove accessor MyEvent(this, EventArgs.Empty); // not supported by an accessor
Wouldn't it be obvious that another accessor called invoke is responsible for this? My thoughts:
class BaseClass { public virtual event EventHandler MyEvent { add; remove; protected invoke; } } class DerivedClass : BaseClass { public override event EventHandler MyEvent { invoke {
I know an old style template that the OnMyEvent(...) method should implement. But there are two important drawbacks to this approach:
- Event code scattered -> less organized code base
- You cannot reorganize an event easily (for example, rename it)
Edit: Obviously, a compiler command already developed for this function (see GetRaiseMethod() ).
source share