.NET实施一个属性过滤器 [英] Implement a Properties Filter in .NET

查看:173
本文介绍了.NET实施一个属性过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不筛选对象的列表。

I have to filter a list of objects.

过滤器应采用逻辑或/与运营商,以及使用括号分组用户组成。

The filter should be composed by users using logical OR / AND operators, and grouping using brackets.

说,是这样的:

说,我们有对象MyObj中和它的属性为prop1,Prop2,Prop3

Say, we have object MyObj and its properties Prop1, Prop2, Prop3

有myObjList用户可以过滤元素,为prop1 ==安勤和Prop2< otherValue或Prop2> thirdvalue

Having myObjList the user could filter elements that Prop1 == aValue AND Prop2 < otherValue OR Prop2 > thirdvalue

有一些已知的(反射)机制,允许管理此类型的过滤操作?

Is there some known (reflection) mechanisms that permits to manage this kind of filtering operations?

推荐答案

建立前pression树,然后编译他们给你,你可以向你要过滤的对象的委托。

Build expression trees, then compile them to give you a delegate which you can apply to the objects you want to filter.

MSDN有一些介绍报道: http://msdn.microsoft.com/ EN-US /库/ bb397951.aspx

MSDN has some introductory coverage: http://msdn.microsoft.com/en-us/library/bb397951.aspx

这篇关于.NET实施一个属性过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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