Expression.Call() overload for calling an instance method expecting a single argument is missing. Is there a reason for this?
Asked Answered
O

0

8

Looking at the documented overloads available for the Expression.Call(), method, I can find the following overloads to obtain an expression node that will perform a call to an instance method expecting:

  1. no arguments
  2. two arguments
  3. three arguments
  4. four arguments
  5. variable arguments via an Expression array
  6. variable arguments via an IEnumerable<Expression>

What would be the rationale for not having an overload expecting a single argument?

In my mind, the method signature for the single argument case would be:

public static MethodCallExpression Call(
    Expression instance,
    MethodInfo method,
    Expression arg0);

I don't see any other overloads that would collide with this method signature, so I really don't get why the method is missing. I understand that the overloads expecting an array or an IEnumerable would allow me to create an Expression for the single-argument case, but that would also apply to the other available overloads so I am curious if there is something I don't see that would explain why this overload is missing.

Overleap answered 20/12, 2016 at 21:40 Comment(6)
as i see in source code there is overload with params Expression[] arguments. that should give you the ability to pass single argument.Edyth
@M.kazemAkhgary yes, I noticed that. In fact that overload allows us to call a method with whatever number of arguments are required, that's why I find odd that they are offering non-array versions for frequent number of arguments except for a single argument.Overleap
Overload list on MSDNGarett
Interestingly, the static version has the internal MethodCallExpression1 but the instance version does not have a corresponding InstanceMethodCallExpresson1, it just uses InstanceMethodCallExpressionN.Armillda
@Armillda Ha, good catch. It's a really interesting decision, if it was deliberate.Cash
The .Net Core source has InstanceMethodCallExpression1 and an internal Expression.Call(e, m, e) that has the comment // COMPAT: This method is marked as non-public to ensure compile-time compatibility for Expression.Call(e, m, null)..Armillda

© 2022 - 2024 — McMap. All rights reserved.