Is it possible to dynamically create delegate to the method currying some parameters (and do it without expression's compile, and DynamicInvoke)?

Viewed 202

Is it possible to dynamically create delegate to the method currying some parameters (and do it without expression's compile, and DynamicInvoke)?

With DynamicInvoke invoke currying would look like

var methodInfo = typeof(MyTools).GetTypeInfo().GetDeclaredMethod(nameof(MyTools.MyMethod));
var delegateType = typeof(Func<,,>).MakeGenericType(typeof(int), typeof(int), typeof(int));
var @delegate = methodInfo.CreateDelegate(delegateType);
var i2 = 1;
var func = (i1) => { return (int)(@delegate.DynamicInvoke(i1, i2)); };

With expression's lambda compile it is also possible but I skip it there.

In my vision methodInfo.CreateDelegate that I search require some additional parameters that would accept i2 , do the currying, and return delegate of type Func<,>.

P.S. The price of lambda compilation is a run-time overhead that we have because of JIT_MethodAccessCheck. When with currying operation I search it should be possible to create deleage without JIT_MethodAccessCheck.

1 Answers
Related