What are the methods of invoking event delegate on inherited members?

It’s rather a c# related question really, I have an OnTargetHit event which can only be fired from where it’s declared. However I would also like to invoke it from its subclasses that contains it.

My current solution:

Base class:

public event Action OnTargetHit;
protected void InvokeOnTargetHit()



this way of doing it is too repetitive as I want to add more events similar to this. Is there a more automated way of doing it to keep my code cleaner?

Thanks in advance.

Is there a more automated way of doing it to keep my code cleaner?

Well, not really as “true” events can only be invoked by the class declaring them. However you “could” drop the “event” keyword and just turn it into a normal delegate. It still can be used the same but can be invoked from everywhere. Though there are a few caveats. First the fact that it can be called from everywhere makes it much easier to accidentally call it from another place that you did not anticipate. Which makes the code a lot more difficult to reason about. Also since it’s just a normal delegate, you could simply replace the delegate with a new value which would erase any other subscriber to the event.

So true "event"s are designed to implement proper encapsulation. So if you want proper error checking you have to use a protected trigger method like you currently have. So it’s up to you.