title: How to call the method from a MethodCallExpression in c#
body: <p>I have a method call expression and try to invoke the method. I figured out a way, but I have problems in retrieving the parameter values since not every argument is described with a ConstantExpression.</p>
  
  <pre><code>Expression&lt;Action&lt;T&gt;&gt; = t =&gt; t.DoSomething(Par0, Par1, Par2);
  MethodCallExpression methodCallExpression = selector.Body 
                                                 as MethodCallExpression;
  
  // get the information which is needed to invoke the method from the provided 
  // lambda expression.
  MethodInfo methodInfo = methodCallExpression.Method;
  object[] arguments = methodCallExpression.Arguments.OfType&lt;ConstantExpression&gt;()
                              .Select(p =&gt; p.Value).ToArray();
  
  // invoke the expression on every item within the enumerable
  foreach (TSource item in source)
  { 
      methodInfo.Invoke(item, arguments);
  }
  </code></pre>
  
  <p>Additionally, I have seen some other ways to invoke the method, now I'm not sure what is the right way to do it.</p>
  
  <pre><code>var func = expression.Compile();
  var success = func.Invoke();
  </code></pre>
  
  <p>So my question is, how can I retrieve the method argument values from <code>methodCallExpression.Arguments</code>? </p>
  
  <p>Or is there an easier way to achieve my goal?</p>