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.

6
  • as i see in source code there is overload with params Expression[] arguments. that should give you the ability to pass single argument. Commented Dec 20, 2016 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. Commented Dec 20, 2016 at 21:54
  • Overload list on MSDN Commented Dec 20, 2016 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. Commented Feb 23, 2018 at 19:06
  • 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).. Commented Sep 24, 2021 at 16:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.