Detect parenthesis in BinaryExpression
<p>I am building a expression analyser from which I would like to generate database query code, I've gotten quite far but am stuck parsing BinaryExpressions accurately. It's quite easy to break them up into Left and Right but I need to detect parenthesis and generate my code accordingly and I cannot see how to do this.</p>

<p>An example [please ignore the flawed logic :)]:</p>

<pre><code>a =&gt; a.Line2 != "1" &amp;&amp; (a.Line2 == "a" || a.Line2 != "b") &amp;&amp; !a.Line1.EndsWith("a")
</code></pre>

<p>I need to detect the 'set' in the middle and preserve their grouping but I cannot see any difference in the expression to a normal BinaryExpression during parsing (I would hate to check the string representation for parenthesis)</p>

<p>Any help would be appreciated.</p>

<p>(I should probably mention that I'm using C#)</p>

<p>--Edit--
I failed to mention that I'm using the standard .Net Expression classes to build the expressions (System.Linq.Expressions namespace)</p>

<p>--Edit2--
Ok I'm not parsing text into code, I'm parsing code into text. So my Parser class has a method like this:</p>

<pre><code>void FilterWith&lt;T&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; filterExpression);
</code></pre>

<p>which allows you to write code like this:</p>

<pre><code>FilterWith&lt;Customer&gt;(c =&gt; c.Name =="asd" &amp;&amp; c.Surname == "qwe");
</code></pre>

<p>which is quite easy to parse using the standard .Net classes, my challenge is parsing this expression:</p>

<pre><code>FilterWith&lt;Customer&gt;(c =&gt; c.Name == "asd" &amp;&amp; (c.Surname == "qwe" &amp;&amp; c.Status == 1) &amp;&amp; !c.Disabled)
</code></pre>

<p>my challenge is to keep the expressions between parenthesis as a single set. The .Net classes correctly splits the parenthesis parts from the others but gives no indication that it is a set due to the parenthesis.</p>
