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

How to throw exception? #48

Open
DNetORM opened this issue Apr 6, 2024 · 1 comment
Open

How to throw exception? #48

DNetORM opened this issue Apr 6, 2024 · 1 comment
Labels

Comments

@DNetORM
Copy link

DNetORM commented Apr 6, 2024

       var valComparer = new ValueComparer() { NullComparison = ValueComparer.NullComparisonMode.Sql };
       var lambdaParser = new NReco.Linq.LambdaParser(valComparer);
       var varContext = new Dictionary<string, object>();
       varContext["pi"] = 3.14M;
       var res=  lambdaParser.Eval("pi>what", varContext); 

I don't have a variable name called what,So I hope I can catch an exception and give me some hints for checking,Instead of directly returning a false to me,How to catch an exception? or tell me variable name error?
@VitaliyMF
Copy link
Contributor

If you need to implement some kind of 'validation' (without actual evaluation of the expression), it is possible to get a list of expression's parameters in this way:

string exprStr = "pi>what";
var lambdaParser = new LambdaParser();
var expr = lambdaParser.Parse(exprStr);
var exprParams = lambdaParser.GetExpressionParameters(expr);

To validate parameters during evaluation you may use LambdaParser.Eval(string expr, Func<string,object> getVarValue) overload and implement your own behaviour inside getVarValue handler.

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

No branches or pull requests

2 participants