Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hmmm... I guess you'd have to parse the tree, checking the node-type and member of each. I'll knock up an example...</p> <pre><code>using System; using System.Linq.Expressions; class Test { public string Foo { get; set; } public string Bar { get; set; } static void Main() { bool test1 = FuncTest&lt;Test&gt;.FuncEqual(x =&gt; x.Bar, y =&gt; y.Bar), test2 = FuncTest&lt;Test&gt;.FuncEqual(x =&gt; x.Foo, y =&gt; y.Bar); } } // this only exists to make it easier to call, i.e. so that I can use FuncTest&lt;T&gt; with // generic-type-inference; if you use the doubly-generic method, you need to specify // both arguments, which is a pain... static class FuncTest&lt;TSource&gt; { public static bool FuncEqual&lt;TValue&gt;( Expression&lt;Func&lt;TSource, TValue&gt;&gt; x, Expression&lt;Func&lt;TSource, TValue&gt;&gt; y) { return FuncTest.FuncEqual&lt;TSource, TValue&gt;(x, y); } } static class FuncTest { public static bool FuncEqual&lt;TSource, TValue&gt;( Expression&lt;Func&lt;TSource,TValue&gt;&gt; x, Expression&lt;Func&lt;TSource,TValue&gt;&gt; y) { return ExpressionEqual(x, y); } private static bool ExpressionEqual(Expression x, Expression y) { // deal with the simple cases first... if (ReferenceEquals(x, y)) return true; if (x == null || y == null) return false; if ( x.NodeType != y.NodeType || x.Type != y.Type ) return false; switch (x.NodeType) { case ExpressionType.Lambda: return ExpressionEqual(((LambdaExpression)x).Body, ((LambdaExpression)y).Body); case ExpressionType.MemberAccess: MemberExpression mex = (MemberExpression)x, mey = (MemberExpression)y; return mex.Member == mey.Member; // should really test down-stream expression default: throw new NotImplementedException(x.NodeType.ToString()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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