How can I dynamically create a delegate with an unknown MethodInfo called on an unknown target with unknown arguments using ILGenerator.Emit (not LambdaExpression.Compile? Because I'm trying to find a more performant solution)
public void CreateDelegate(MethodInfo mi, object target, object[] arguments)
{
var method = new DynamicMethod("Temp", typeof(void), Type.EmptyTypes);
var generator = method.GetILGenerator();
// Make the method call mi on target with arguments
// ...
method.CreateDelegate(typeof(Action));
}
Maybe you are looking something like this? If by Unknown you mean Any:
Or, you can just reference Platform.Reflection (version 0.1.0 or later) NuGet package. And use Platform.Reflection.DelegateHelpers.