使用表达式求值器在多个 Enumerable 上执行动态 LINQ 字符串 - DLR / NCalc / Flee?
我有一个具有属性的通用对象:
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 查询这些枚举,但这些查询是动态并且是字符串形式,例如
People.
Where(a["age"] > 45 && Cities.Where(b["Country"] == "IE").Contains(a["home"]).
Sum(c["Income"])
有什么建议吗?我目前正在使用 Ncalc 以及许多调用 Linq 代码的 switch 语句...
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"));
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"])
Any recommendations? I'm currently using Ncalc with lots of switch statements that call Linq code...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 动态 Linq
Have a look at Dynamic Linq