My current situation looks like this:
I have these two delegates in a separate file:
public delegate void EventHandler(Object obj, EventArgs e);
public delegate void OtherEventHandler(Object obj, OtherEventArgs e);
I have an Event class that look like this:
class Event {
EventHandler _handler;
public Event(EventHandler handler) {
_handler = handler;
}
}
I have another class that inherits Event this way:
class OtherEvent : Event {
OtherEventHandler _handler;
public OtherEvent (OtherEventHandler handler) : base(handler) {
_handler = handler;
}
}
This one is where the problem occurs. The error is with the part on base(handler). Because handler in OtherEvent is an OtherEventHandler, the base class cannot accept it; the base class only accepts EventHandler.
My intention is to have a “generic” delegate such that when OtherEvent inherits the methods from Event, OtherEvent still has the flexibility to use its own type of delegate with different parameters from its parent for the handler class field.
What can I do to achieve my intention?
Whats wrong with usage of default delegate
EventHandler<TEventArgs>? It can be parametrized with any type, inherited fromEventArgs.Also I don’t really understand purpose of
Eventclass. You can define events simply this way: