I posted a month or so ago and never got a response. So I'm trying
again.
I just moved over to C#2. In 1.1 I implemented a generic event
handler strategy by emitting a handler of the correct signature type.
However, with Covariance/Contravariance in C#2 I hoped to clean
things
up.
Since this works in 2.0:
button1.Click += GenericEventHandler; // Just a normal EventHandler
button1.MouseDown += GenericEventHandler; // a MouseEventHandler
private void GenericEventHandler(object sender, EventArgs args)
{
}
I had hoped to be able to do something similar to the above code via
Reflection. So I tried this:
eventInfo.AddEventHandler(instance, new
EventHandler(GenericEventHandler);
But if the eventInfo.EventHandlerType is not a basic EventHandler I
receive the following error:
Object of type 'System.EventHandler' cannot be converted to type
'System.Windows.Forms.MouseEventHandler'.
Is there any way to make this happen?
Thanks