Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public void RegisterAction(ActionData actionData, EventInfo eventInfo, Control control) { MethodInfo methodInfo = eventInfo.EventHandlerType.GetMethod("Invoke"); List&lt;Type&gt; ps = new List&lt;Type&gt;(); ps.Add (typeof (ActionData)) ; foreach (ParameterInfo info in methodInfo.GetParameters()) { ps.Add(info.ParameterType); } DynamicMethod method = new DynamicMethod("Adapter", typeof (void), ps.ToArray(), GetType(), true); // compatible signatures for ExecuteAction // (assuming you aren't interested in sender and eventArgs): // static void ExecuteAction (ActionData) ; // void ActionData.ExecuteAction () ; MethodInfo miExecuteAction = &lt;...&gt; ; ILGenerator generator = method.GetILGenerator(); generator.Emit (OpCodes.Ldarg_0) ; generator.Emit (OpCodes.Call, miExecuteAction) ; generator.Emit (OpCodes.Ret) ; // if you want to pass this to ExecuteAction, // you'll need to put it into actionData. Delegate proxy = method.CreateDelegate(eventInfo.EventHandlerType, actionData); eventInfo.AddEventHandler(control, proxy); } </code></pre> <p><strong>Edit</strong>: come to think of it, if all your events follow the (sender, args) pattern, you don't even need do mess with SRE:</p> <pre><code>public static void Execute&lt;T&gt; (ActionData data, object sender, T args) where T : EventArgs { ExecuteAction (data) ; } public void RegisterAction (ActionData actionData, EventInfo eventInfo, Control control) { MethodInfo compatibleMethod = typeof (this).GetMethod ("Execute", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod ( eventInfo.EventHandlerType.GetMethod ("Invoke").GetParameters ()[1].ParameterType)) ; eventInfo.AddEventHandler (control, Delegate.CreateDelegate (eventInfo.EventHandlerType, actionData, compatibleMethod)) ; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload