我有一个带属性的通用对象:
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语句...