I need to generate an event handler based on an EventInfo object in runtime and call a method within that event handler. Something like the following:
public void RegisterAction(ActionData actionData, EventInfo eventInfo,
Control control)
{
MethodInfo methodInfo = eventInfo.EventHandlerType.GetMethod("Invoke");
List<Type> ps = new List<Type>();
foreach (ParameterInfo info in methodInfo.GetParameters())
{
ps.Add(info.ParameterType);
}
DynamicMethod method = new DynamicMethod("Adapter",
typeof (void),
ps.ToArray(),
GetType(),
true);
ILGenerator generator = method.GetILGenerator();
// Here I need to generate a method to do the following:
// ExecuteAction(actionData);
// Then I can use this runtime method as an event handler and
// bind it to the control
Delegate proxy = method.CreateDelegate(eventInfo.EventHandlerType, this);
eventInfo.AddEventHandler(control, proxy);
}
I need help in generating the IL code for the commented part.