Skip to content

Conversation

@stg609
Copy link
Contributor

@stg609 stg609 commented Jun 19, 2021

TL;DR

Fix if member == null, and EvaluateVariable set Value = null on purpose, but throw "object has no public Property or Member"

Details

If I evaluate a non existed property like below, an exception will throw.

ExpressionEvaluator evaluator = new ExpressionEvaluator(); evaluator.Variables = new Dictionary<string, object>() { { "obj", new { }} }; // throw an exception like "object has no public Property or Member x ..." Console.WriteLine(evaluator.Evaluate("obj.x")); 

However, our requirement is return null instead of the exception. So I made use of the EvaluateVariable like below :

evaluator.EvaluateVariable += Evaluator_EvaluateVariable; private static void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg e) { e.HasValue = true; e.Value = null; } 

No luck.

…se, but throw "object has no public Property or Member"
@codingseb codingseb merged commit 05cc3b7 into codingseb:master Jun 21, 2021
@codingseb
Copy link
Owner

Thank a lot for this @stg609.
I will publish it with next version. I just need to correct some other issues.

codingseb added a commit that referenced this pull request Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants