title: System.Linq.Expressions: Binding LambdaExpression inputs at runtime
body: <p>Consider the following setup:</p>
  
  <pre><code>class A { public int x; }
  class B { public int y; }
  
  static class Helper
  {
      public static Expression&lt;Func&lt;B&gt;&gt; BindInput(
          Expression&lt;Func&lt;A, B&gt;&gt; expression,
          A input)
      {
          //TODO
      }
  }
  
  static void Main(string[] args)
  {
      Expression&lt;Func&lt;B&gt;&gt; e = Helper.BindInput(
          (A a) =&gt; new B { y = a.x + 3 },
          new A { x = 4 });
  
      Func&lt;B&gt; f = e.Compile();
      Debug.Assert(f().y == 7);
  }
  </code></pre>
  
  <p>What I want to do in the method <code>BindInput</code> is transform the expression to have <code>input</code> embedded into it. In the example usage in <code>Main</code>, the resulting expression <code>e</code> would be</p>
  
  <pre><code>() =&gt; new B { y = input.x + 3 }
  </code></pre>
  
  <p>where <code>input</code> is the second value that was passed into <code>BindInput</code>.</p>
  
  <p>How would I go about doing this?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I should add that the following expression <code>e</code> is <strong>not</strong> what I'm looking for:</p>
  
  <pre><code>((A a) =&gt; new B { y = a.x + 3 })(input)
  </code></pre>
  
  <p>This would be fairly trivial to obtain because it just involves adding a layer on top of the existing expression.</p>