title: Parse string to C# lambda Func
body: <p>Is there a way to convert string representation of lambda to a lambda Func?</p>
  
  <pre><code>Func&lt;Product, bool&gt; func = Parse&lt;Product, bool&gt;("product =&gt; product.Name.Length &gt; 0");
  </code></pre>
  
  <p>I tried Dynamic LINQ but it doesn't work as expected - for example it doesn't expect lambda syntax =>.</p>
  
  <p>Summary of answers:</p>
  
  <ul>
  <li>writing my own C# compiler - very funny</li>
  <li>firing up external compiler (like csc.exe) - very slow</li>
  <li>using DLINQ - as I said I don't see how it can parse <strong>lambda</strong> expressions</li>
  </ul>
  
  <p>Why do I need this: because there's no way to pass lambdas to custom attributes like</p>
  
  <pre><code>[Secure(role =&gt; role.CanDoThis &amp;&amp; role.AllowedCount &gt; 5)]
  </code></pre>
  
  <p>So as a workaround I'd like to pass lambda as string: "role => role.CanDoThis &amp;&amp; role.AllowedCount > 5". But seems like I'll have to use DLINQ like this: "CanDoThis &amp;&amp; AllowedCount > 5" - since that's the syntax it understands. But my question was about true lambdas, I've already used DLINQ at the time of asking.</p>