title: Parsing Conditional Expressions to String
body: <p>I'm looking for a way of parsing a conditional expression to a string.</p>
  <p>The best example I can think of is LINQ-to-SQL. It uses ExpressionVisitors to format &quot;Where&quot; clauses. Example:</p>
  <pre><code>from a in b where a.x == 5 &amp;&amp; a.y &lt; 3 select a
  </code></pre>
  <p>That would translate into the following string (approximately, MSSQL is not current for me):</p>
  <pre><code>&quot;SELECT * FROM b WHERE x = 5 AND y &lt; 3&quot;
  </code></pre>
  <p>From what I've read, this was done using the ExpressionVisitor class, as explained in this article: <a href="https://docs.microsoft.com/en-us/archive/blogs/mattwar/linq-building-an-iqueryable-provider-part-ii" rel="nofollow noreferrer">Link</a></p>
  <p>Now the problem is that I don't use LINQ, but I need this particular functionality. Is there a way of parsing a condition like that? I'm willing to do anything with reflection, delegates, lambda, etc.</p>
  <p>Honestly, I don't think it's possible, but my <em>brain is a bit fried</em> (read: be nice if the question is ridiculous), so I figured I might just as well give S/O a try.</p>
  <p><strong>EDIT</strong>: Final usage example:</p>
  <pre><code>// Usage:
  foo.Bar(foo =&gt; foo.X == 5 &amp;&amp; foo.Y &lt; 3)
  
  // Ideal string output (variable name (foo) is not needed):
  &quot;foo.X == 5 &amp;&amp; foo.Y &lt; 3&quot;
  </code></pre>
  <p><strong>EDIT 2</strong>: Yes, a number can be lower than 3 and equal to 5. Told you my brain is fried.</p>