dynamic expresso - Ability to set the context of the expression -


Is there a way to set the context of the expression, so that we can do something like this:

  interpreter.Eval ("first name", new parameter ("person", new {first name = "homer", last name = "Simpson"}));  
  interpreter.Eval ("person.FirstName", new parameter ("person", new {first name = "homer", last name = "Simpson"}));   

Maybe we have another option which is to use the first parameter as the reference of the expression.

I think that it may also be another version of the parse and the Evil Methods that assumes the expression text and ordinary objects in terms of expression.

Besides this, lack of support for more dynamic types, I really like this library. I did something similar in the way, but did not add support for extension methods and general method calls.

Thanks to the great library, Neal

There is no built-in solution but you It can be simulated in many ways:

Option 1: An expression injection var performance = new {first name = "homer" }; Var WorkContactCotex Expression = Expression. Constant (desired); Var firstNameExpression = expression Property (Working Tickets Expert, "Firstname"); Variable Interpreter = New Interpreter (); Interpreter SAT Expression ("Firstname", first name expression); Assurance.Arux (Performance first name, interpreter. Aval ("first name"));

Actually I inject an expression using the SetExpression method. Expression of injection is the property that you want to be available.

Option 2: Use this / me / this variable

You can inject a variable that will include your working object I call this (or me or this depends on the application}).

  var workingContext = new {first name = "homer"}; Variable Interpreter = New Interpreter (); Interpreter Set Variable ("This", Performance); Decide. Arial (performance first name, interpreter. Aval ("this.FirstName"));   

Option 3: A combination of previous solutions

  var workingContext = new {FirstName = "homer"}; Variable Interpreter = New Interpreter (); Interpreter Set Variable ("This", Performance); Var firstNameExpression = interpreter.Parse ("this.FirstName"). LambdaExpression.Body; Interpreter SAT Expression ("Firstname", first name expression); Assurance.Arux (Performance first name, interpreter. Aval ("first name"));   

The first solution is equivalent to the solution but I create the expression using the parser.

Consider that all solutions assume that you have an interpreter example for each reference.

Disclaimer: I am the author of the Dynamic Expresso Library.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -