Consider:
someControl.Click += delegate { Foo(); };
The arguments of the event are irrelevant, I don't need them and I'm not interested in them. I just want Foo() to get called. There's no obvious way to do the same via reflection.
I'd like to translate the above into something along the lines of
void Foo() { /* launch missiles etc */ }
void Bar(object obj, EventInfo info)
{
Action callFoo = Foo;
info.AddEventHandler(obj, callFoo);
}
Also, I don't want to make the assumption that the type of object passed to Bar strictly adheres to the guidelines of using the EventHander(TArgs) signature for events. To put it simply, I'm looking for a way to subscribe an Action to any handler type; less simply, a way to convert the Action delegate into a delegate of the expected handler type.
Usage:
How about this?