I have a generic object which uses a dictionary to store the properties:
class MyObject
{
Dictionary<string, object> Properties = new Dictionary<string, object>();
internal GetValue(string name) { return Properties[name]; }
internal SetValue(string name, object value) { Properties[name] = value; }
}
MyObject obj1 = New MyObject();
obj1.SetValue("Name", "John");
obj1.SetValue("Age", 23);
MyObject obj2 = New MyObject();
obj2.SetValue("Name", "Mary");
obj2.SetValue("Age", 24);
List<MyObject> ObjList = new List<MyObject>();
ObjList.Add(obj1);
ObjList.Add(obj2);
Now we need to query the ObjList to find certain entries. Dynamic LINQ (Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)) seems to be perfect, but from what I can see it requires that the object have pre-defined properties.
We want to do queries like:
ObjList.Where("Name == 'Mary' || Age < 24");
Any token (e.g. Name, Age) should call "GetValue". Any suggestions?
Obviously the where statement is completely up to the user and is not fixed.