本文介绍了如何测试表达式的相等性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何测试这两个表达式与此示例相同
How to test that two expressions are the same like this sample
string firstname = "Ahmed";
Expression<Func<string, bool>> exp1 = (s) => s.Contains(firstname);
Expression<Func<string, bool>> exp2 = (s) => s.Contains(firstname);
Console.WriteLine(exp1 == exp2);//print false as two references are no equal
现在如何确保expression1等于expression2,因为它们具有相同的条件?
now how to ensure that expression1 equals to expression2 , as they have the same criteria?
推荐答案
是 ExpressionEqualityComparer
的代码,可以显示如何执行。
Here is the code for ExpressionEqualityComparer
which can show how to do it.
这篇关于如何测试表达式的相等性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!