No, unfortunately not.
If you look at Reactive Extensions, that suffers from a similar problem. Three options they use (IIRC - it's been a while since I've looked):
- Pass in the corresponding
EventInfo
and call it with reflection
- Pass in the name of the event (and the target if necessary) and call it with reflection
- Pass in delegates for subscription and unsubscription
The call in the latter case would be something like:
SubscribeAndDoUnsubscribe(elements,
handler => e.Click += handler,
handler => e.Click -= handler);
and the declaration would be:
void SubscribeDoAndUnsubscribe(
IEnumerable elements,
Action> subscription,
Action> unsubscription)
where TEventArgs: EventArgs