使用表达式计算器在多个Enumerables上执行动态LINQ字符串-DLR/NCalc/Flee? [英] Using expression evaluator to execute dynamic LINQ strings on multiple Enumerables - DLR / NCalc / Flee?

查看:88
本文介绍了使用表达式计算器在多个Enumerables上执行动态LINQ字符串-DLR/NCalc/Flee?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有属性的通用对象:

I have a generic object with properties:

Class MyObject
{
    public Dictionary<string, Object> properties = new Dictionary<string, Object>();
    public object this[string name] { get { return properties[name]: null; }
}
List<MyObject> People= new List<MyObject>();
People.Add(new MyObject(age = 50, home = "Dublin", name = "Bob", Income = "50"));
People.Add(new MyObject(age = 45, home = "London", name = "Tim", Income = "90"));

List<MyObject> Cities= new List<MyObject>();
Cities.Add(new MyObject(City = "Dublin", Country = "IE"));
Cities.Add(new MyObject(City = "London", Country = "UK"));

我希望能够使用Linq查询这些Enumerables,但是这些查询是动态的,并且以字符串形式出现,例如

I would like to be able to query these Enumerables by using Linq, but these queries are dynamic and would be in strings, e.g.

People.
Where(a["age"] > 45 && Cities.Where(b["Country"] == "IE").Contains(a["home"]).
Sum(c["Income"])

有什么建议吗?我目前正在使用 Ncalc 和许多调用Linq代码的switch语句...

Any recommendations? I'm currently using Ncalc with lots of switch statements that call Linq code...

推荐答案

看看 查看全文

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