I need to generate an IQueryable LINQ expression from a string. First examine class Foo
public class Foo
{
public int Type { get; set; }
public int Value { get; set; }
public string Name { get; set; }
}
Method ToFoo would then take anything inside {} and return an IQueryable list.
So ToFoo("{1, >, 10}")
would return an IQueryable list. I have this part working already. What I'm missing is the Parsing method to combine the various IQueryable objects.
IQueryable<Foo> context = GetAllFoos(....);
string myInput = "({e1} | ({e2} & {e3})) | {e4}";
var result = SomeParser(myInput, context);
foreach(var x in result)
WriteLine(x.Bar);
The only allowable operations would be & (Intersect) and | Union.
So in the example above SomeParser would return something like:
result = ToFoo("{e1}").Union(
ToFoo("{e2}").Intersect(ToFoo("{e3}")
).Union(ToFoo("{e4}");
I was looking at ANTLR, but I'm unsure if this would require Java, which is a non-starter for deployment reasons. But I'm not sure if ANTLR would allow me to define my grammar and would build my c# classes, thus not having to require Java installed on the target systems.
In any case, it looks like I need to build an expression tree where I can navigate through the structure and UNION/INTERSECT the results returned from ToFoo