title: Replace parameter in lambda expression
body: <p>Considering this code:</p>
  
  <pre><code>public class Foo
  {
      public int a { get; set; }
      public int b { get; set; }
  }
  
  private void Test()
  {
      List&lt;Foo&gt; foos = new List&lt;Foo&gt;();
      foos.Add(new Foo());
      foos.Add(new Foo());
      Expression&lt;Func&lt;Foo, int&gt;&gt; exp0 = f =&gt; f.a * f.b;
      Expression&lt;Func&lt;int&gt;&gt; exp1 = () =&gt; foos[0].a * foos[0].b;
      Expression&lt;Func&lt;int&gt;&gt; exp2 = () =&gt; foos[1].a * foos[1].b;
  }
  </code></pre>
  
  <p>How can you take <code>exp0</code> and turn it into two expressions identical to <code>exp1</code> and <code>exp2</code>. Note that I don't want to just evaluate <code>exp0</code> for each <code>Foo</code> in <code>foos</code>, but instead get two new expressions. </p>
  
  <p><strong>[Update]</strong>:</p>
  
  <p>Basically, I want to be able to expand or "flatten" an expression passed to a <code>Linq</code> extension method such as <code>Sum</code> into one expression per item in the enumeration since these enumerations will be static, and because I already have code that reads expressions that don't take parameters (and then turns them into another language).</p>
  
  <p>I'm using the <code>MetadataToken</code> as a references to properties that have a certain attribute (in this case <code>a</code> and <code>b</code> would have this attribute) and using it with a dictionary that correlates C# properties to another language's variables:</p>
  
  <pre><code>Foo foo = new Foo();
  Expression&lt;Func&lt;int&gt;&gt; exp = () =&gt; foo.a * foo.a + foo.b;
  string result1 = GetResult(exp); // gets "v_001 * v_001 + v_002"
  
  List&lt;Foo&gt; foes = new List&lt;Foo&gt;();
  foes.Add(new Foo());
  foes.Add(new Foo());
  Expression&lt;Func&lt;int&gt;&gt; exp2 = () =&gt; foes.Sum(f =&gt; f.a * f.a + f.b);
  string result2 = GetResult(exp2); // should get "(v_001 * v_001 + v_002) + (v_003 * v_003 + v_004)"
  </code></pre>