Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Matthew writes, you'll need process the expression tree. This can be done using <code>ExpressionVisitor</code>, which allows you to write some code for every type of node in the expression tree. However, if you want to support only simple expressions (such as the one in your example), then you could use <code>NodeType</code> property to process it. </p> <p>The structure could be something like:</p> <pre><code>static void HandlePrimitive(Expression e) { // TODO: Handle primitive cases (&gt;, &lt;, &lt;=, !=, &gt;=, ..) Console.WriteLine(e.NodeType); } static void Process(Expression e) { if (e.NodeType == ExpressionType.OrElse) { // Process left subexpression (one (in)equality) as primitive // and right subexpression recursively (it may be either primitive // or another OrElse node. var be = e as BinaryExpression; HandlePrimitive(be.Left); Process(be.Right); } else HandlePrimitive(e); } Expression&lt;Func&lt;Product,bool&gt;&gt; f = a =&gt; a.ProductType == "tea" || a.Price &lt;= 5; Process(f.Body); </code></pre> <p>The <code>Process</code> method recursively iterates over all the subexpressions composed using the "or" operator (you could support "and" similarly). The <code>HandlePrimitive</code> method would deal with expressions that may be composed using <code>||'s. These are other</code>BinaryExpression<code>values (e.g.</code>Equal<code>or</code>LessThanEqual<code>). You'll need to look at their</code>Left<code>and</code>Right` property to find out the property name and value to be compared against.. but it shouldn't be too much work for this simple type of expressions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload