Is there a way to set the context of the expression in Dynamic Expresso library, so that we can do something like the following:
interpreter.Eval("FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
rather than
interpreter.Eval("person.FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
Maybe we could have a another option that would say that the first parameter is to be used as the context for the expression.
I guess there could also be another version of Parse and Eval methods that simply takes the expression text and a simple object value that will serve as the expression context.
Other than that and the lack of support for dynamic types, I am really liking this library. I had worked on something similar, but had not added support for extension methods and generic method calls.
Thanks for the great library, Neal
There isn't a built-in solution but you can simulate it in many ways:
Option 1: Inject an expression
Basically I inject an expression using
SetExpressionmethod. The injected expression is the property that you want to be available.Option 2: Use this/me/it variable
You can inject a variable that will contain your working object. I usually call it
this(ormeoritdepending on the application).Option 3: A combination of the previous solutions
Equal to the first solution but I generate the expression using the parser itself.
Consider that all solutions assume that you must have an
Interpreterinstance for each context.Disclaimer: I'm the author of Dynamic Expresso library.