Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can have a look at the type <a href="https://github.com/lytico/db4o/blob/master/db4o.net/Db4objects.Db4o.Linq/Db4objects.Db4o.Linq/Expressions/ExpressionEqualityComparer.cs" rel="nofollow noreferrer">ExpressionEqualityComparer</a> that is used inside <a href="http://evain.net/blog/articles/2008/02/06/an-elegant-linq-to-db4o-provider-and-a-few-linq-tricks" rel="nofollow noreferrer">Linq to db4o</a>. It implements the interface IEqualityComparer&lt;T&gt;, so it's usable for generic collections, as well as for a standalone usage.</p> <p>It uses the type <a href="https://github.com/lytico/db4o/blob/master/db4o.net/Db4objects.Db4o.Linq/Db4objects.Db4o.Linq/Expressions/ExpressionComparison.cs" rel="nofollow noreferrer">ExpressionComparison</a> to compare two Expressions for equality, and <a href="https://github.com/lytico/db4o/blob/master/db4o.net/Db4objects.Db4o.Linq/Db4objects.Db4o.Linq/Expressions/HashCodeCalculation.cs" rel="nofollow noreferrer">HashCodeCalculation</a>, to compute a hashcode from an Expression.</p> <p>It all involves visiting the expression tree, so it can be pretty costly if you do it repeatedly, but it can also be quite handy.</p> <p>The code is available under the GPL or the <a href="http://www.db4o.com/about/company/legalpolicies/docl.aspx" rel="nofollow noreferrer">dOCL</a></p> <p>For instance, here's your test:</p> <pre><code>using System; using System.Linq.Expressions; using Db4objects.Db4o.Linq.Expressions; class Test { static void Main () { Expression&lt;Func&lt;int, bool&gt;&gt; a = x =&gt; false; Expression&lt;Func&lt;int, bool&gt;&gt; b = x =&gt; false; Expression&lt;Func&lt;int, bool&gt;&gt; c = x =&gt; true; Expression&lt;Func&lt;int, bool&gt;&gt; d = x =&gt; x == 5; Func&lt;Expression, Expression, bool&gt; eq = ExpressionEqualityComparer.Instance.Equals; Console.WriteLine (eq (a, b)); Console.WriteLine (eq (a, c)); Console.WriteLine (eq (a, d)); } } </code></pre> <p>And it indeed prints True, False, False.</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