title: Invoking a MethodCallExpression with named parameter constants
body: <p>Say I have some function like so</p>
  
  <pre class="lang-c# prettyprint-override"><code>public string TestValue(string hello, Guid world)
  {
      return hello + world;
  }
  </code></pre>
  
  <p>Assuming that <code>objectParams</code> is a dictionary of object <code>Dictionary&lt;string, object&gt;</code>  that map the parameter name to the value, I'm currently matching the parameter values to the method name like so:</p>
  
  <pre class="lang-c# prettyprint-override"><code>var method = this.GetType().GetMethod("TestValue");
  var methodParameters = method.GetParameters();
  var paramMatcher = (from paramValue in objectParams
                      from methodParam in methodParameters
                      where param.Key == clrParam.Name
                      select (name: clrParam.Name,
                              type: clrParam.ParameterType,
                              value: paramValue.Value));
  </code></pre>
  
  <p>I then build the expression to call the method <code>TestValue</code> like so, but this is the part I'm having trouble with. </p>
  
  <pre class="lang-c# prettyprint-override"><code>var paramExpress = (from param in paramMatcher
                      select Expression.Assign(Expression.Parameter(param.type, param.name), Expression.Constant(param.value)));
  
  Func&lt;object&gt; result = Expression.Lambda&lt;Func&lt;object&gt;(Expression.Call(Expression.Constant(this),
      method, paramExpress)).Compile();
  var res = result.Invoke(); //should return 'somestringxxxxxxx-xxxx...etc'
  </code></pre>
  
  <p>The issue is that I can't guarantee that the parameter values are in call order so I want to rely on the name of the parameters to call. I'm not sure on how to assign the constant values to their parameter expressions properly. Running this code results in the exception <code>System.InvalidOperationException: 'variable 'hello' of type 'System.String' referenced from scope '', but it is not defined'</code> when compiling the lambda.</p>