Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top