如何测试表达式的相等性 [英] How to test expressions equality

查看:163
本文介绍了如何测试表达式的相等性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

最有效的方法来测试lambda表达式的相等性

如何检查两个Expression< Func< T,bool>>相同

如何测试这两个表达式与此示例相同

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.

https://source.db4o.com/db4o/trunk/db4o .net / Db4objects.Db4o.Linq / Db4objects.Db4o.Linq /表达式/

这篇关于如何测试表达式的相等性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆