title: Expression Trees and Invoking a Delegate
body: <p>So I have a <code>delegate</code> which points to some function which I don't actually know about when I first create the <code>delegate</code> object. The object is set to some function later.</p>
  
  <p>I also then want to make an expression tree that invokes the delegate with an argument (for this question's sake the argument can be <code>5</code>). This is the bit I'm struggling with; the code below shows what I want but it doesn't compile.</p>
  
  <pre><code>Func&lt;int, int&gt; func = null;
  Expression expr = Expression.Invoke(func, Expression.Constant(5));
  </code></pre>
  
  <p>For this example I could do (this is practical since I need to build the expression trees at runtime):</p>
  
  <pre><code>Func&lt;int, int&gt; func = null;
  Expression&lt;Func&lt;int&gt;&gt; expr = () =&gt; func(5);
  </code></pre>
  
  <p>This makes <code>expr</code> become:</p>
  
  <pre><code>() =&gt; Invoke(value(Test.Program+&lt;&gt;c__DisplayClass0).func, 5)
  </code></pre>
  
  <p>Which seems to mean that to use the <code>delegate</code> <code>func</code>, I need to produce the <code>value(Test.Program+&lt;&gt;c__DisplayClass0).func</code> bit.</p>
  
  <p>So, how can I make an expression tree which invokes a delegate?</p>