Code Inspection: Invocation of polymorphic field-like event
Consider the following piece of code:
The above block of code uses an overriding event declaration to override the implementation of the add and remove methods on an event. The field itself will then exist in two separate instances - one in
Base and one in
Derived. As a consequence, when working with
Derived, you are likely to never instantiate the
MyEvent unless you explicitly set it to some value. And, as a result of that, the behavior in the case when the event is raised in the base class would differ from that in the derived class.
The simplest way to resolve the above situation is to simply get rid of the override and instead to create an event-firing method in the base class. For example: