使用表达式求值程序在多个Enumerables上执行动态LINQ字符串 - DLR / NCalc / Flee?

时间:2010-08-09 11:44:25

标签: c# linq generics dynamic-data

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

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,但这些查询是动态并且会在字符串中,例如

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

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

1 个答案:

答案 0 :(得分:1)

查看Dynamic Linq