15

Possible Duplicate:
How to check if two Expression<Func<T, bool>> are the same

I need to compare two lambda expressions, to check equality. Basicly, the two following lambda are identical:

Expression<Func<int, bool>> exp1 = (Foo f) => f.Bar().StartsWith("F");
Expression<Func<int, bool>> exp2 = (Foo b) => b.Bar().StartsWith("F");

How can I check if exp1 does the same thing that exp2 does?

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
Jonathas Costa
  • 1,006
  • 9
  • 27
  • 4
    Does equality mean semantically the same, or that they both produce the same result? – Davin Tryon Dec 26 '12 at 17:29
  • for the reference, there is a solution [link](http://stackoverflow.com/a/24528357/2528649), I have checked it with this code, works well. – neleus Jul 02 '14 at 10:29

1 Answers1

3

You might need to use IComparer or mock classes

View c-sharp-lambda-expressions-and-icomparer and comparing-simple-lambda-expressions

Community
  • 1
  • 1
Rahul Ranjan
  • 1,028
  • 1
  • 10
  • 27