一种使用谓词委托的所有查询的方法.这是一个疯狂的主意吗? [英] One method for all queries using predicate delegate. Is this a crazy idea?

查看:69
本文介绍了一种使用谓词委托的所有查询的方法.这是一个疯狂的主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个具有以下属性的对象集合:


时间
位置频率

我想实现一个方法调用根据不同的标准从我的收藏夹中获取对象的列表:

我可以根据以上任一属性进行查询.我还可以使用这些属性的布尔表达式运行查询.

无论输入条件如何,我都希望使用单个方法调用来运行查询.

我调查了谓词T通用委托,但无法弄清楚如何定义一个可以捕获我所有输入条件的委托.例如,我想到使用以下方法签名:

Say I have a collection of objects with the following properties:

Key
Time
Location
Frequency

I will like to implement a single method call to get a list of objects from my collection based based on different criteria:

I could query based on either of the above propeties.  I could also run a query with a boolean expression of these properties.

I will like to use a single method call to run my query, regardless of the input conditions. 

I have looked into the Predicate<T> Generic Delegate, but could not figure out how one can define a single delegate that would capture all of my input conditions.  For example, I thought of using the following method signature:

代码段

推荐答案

您可以将代表列表传递到方法然后让该方法调用它们中的每一个?
Can you pass in a list of delegates into a method then have that method call each one of them?


这篇关于一种使用谓词委托的所有查询的方法.这是一个疯狂的主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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