Limited options for accessing events in derived classes?
-
01-10-2019 - |
문제
Im refactoring a class, and moving sections into a base class.
I have a few events similar to
public event EventHandler GridBinding;
Which are now in the base class, but i am finding i cannot now check to see if the event is null in my derived class. Doing so gives me the error:
The event 'xyz.GridBinding' can only appear on the left hand side of += or -= (except when used from within the type 'xyz._MyBaseClass').
Is this correct, am i missing anything, or is there any way to get around this or is writing an accessor the only way to do this? I am using c#/.net 4.0
해결책
No, you cannot get around this.
The proper way is to declare protected methods in the class containing the events, so you can fire them from any derived class, if needed.
제휴하지 않습니다 StackOverflow