Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for a global Context #45

Closed
TheoVC opened this issue Jan 21, 2020 · 3 comments
Closed

Support for a global Context #45

TheoVC opened this issue Jan 21, 2020 · 3 comments

Comments

@TheoVC
Copy link

TheoVC commented Jan 21, 2020

Receiving a list of variables is helpfull, but it would be great if instead of this

var eval = new ExpressionEvaluator(variables);

the library could receive an object which would be the context. (similar to what roslyn does)

var eval = new ExpressionEvaluator(Person1);

then all the properties, variables and methods would be directly accessible

eval.Evaluate(" Name + \" \" + LastName ");
eval.Evaluate(" aPersonMethod() + 10");

where Person1 is an instance of the class

public class Person{
   public string Name {get;set;}
   public string LastName {get;set;}
   public int aPersonMethod(){
      return 10;
   }
}
@codingseb
Copy link
Owner

I will see what it take to do it.
For now I do not have a lot of time for ExpressionEvaluator.
but the idea is good.

@codingseb
Copy link
Owner

I just published version 1.4.6.0 that implement a Context object in addition to the variables dictionary.
(See Context object on the wiki)
2 new constructors are available and a property Context.

It's an easy modification that allow this and I only made a few tests.
So don't hesitate to open new issues if you find some bugs with this.

For now I close this issue.
Thanks for this idea. I think it's a nice enhancement for ExpressionEvaluator.

@TheoVC
Copy link
Author

TheoVC commented Feb 10, 2020

this is amazing... now it's just perfect.
it's much simpler and easy to understand than an ANTLR version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants