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.

BlueStrat
  • 2,202
  • 17
  • 27
  • as i see in source code there is overload with `params Expression[] arguments`. that should give you the ability to pass single argument. – M.kazem Akhgary Dec 20 '16 at 21:49
  • 1
    @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. – BlueStrat Dec 20 '16 at 21:54
  • [Overload list on MSDN](https://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.call.aspx) – Jeppe Stig Nielsen Dec 20 '16 at 23:01
  • Interestingly, the static version has the internal `MethodCallExpression1` but the instance version does not have a corresponding `InstanceMethodCallExpresson1`, it just uses `InstanceMethodCallExpressionN`. – NetMage Feb 23 '18 at 19:06
  • @NetMage Ha, good catch. It's a really interesting decision, if it was deliberate. – NPras Nov 27 '18 at 22:40
  • 1
    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).`. – NetMage Sep 24 '21 at 16:18

0 Answers0