I'm trying to convert a method to an internal (and nested) delegate type. The problem is that because it's internal, Delegate.CreateDelegate
fails and throws an exception.
System.ArgumentException:
Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
Here's the relevant code for how I'm trying to accomplish this.
// The method to convert to the internal delegate type
private bool OnEnterMenuMode(object sender, EventArgs e);
// The internal nested delegate type
public sealed class KeyboardNavigation {
internal delegate bool EnterMenuModeEventHandler(object sender, EventArgs e);
// The code used to create the delegate
object instance; // Owner of OnEnterMenuMode
EventInfo eventInfo; // The internal event
Delegate.CreateDelegate(eventInfo.EventHandlerType, instance,
((Action<object,EventArgs>)method).Method);
Aucun commentaire:
Enregistrer un commentaire