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

ExpressionEvaluator method should use IDictionary or IReadOnlyDictionary input type #29

Closed
kasajian opened this issue Mar 28, 2019 · 3 comments

Comments

@kasajian
Copy link

Small request.

The "ExpressionEvaluator()" method that takes a Dictionary of variables, I'd like to suggest that it instead take IDictionary or, better yet, IReadOnlyDictionary. The reason is because the host code may already have a set of "variables" in a dictionary but the "value" item of each entry is not the variable value, but a different object that contains the value, in addition to other things. Passing that directly to your code wouldn't work because your code expects the Value of the dictionary entry to be an actual intrinsic value such as an int or a double. So today, I have to create a separate dictionary just for the evaluator which is wasteful. If the ExpressionEvaluator code took on an interface instead, I could implement that interface in my object that used the existing dictionary internal to our code.

In general, parameters to methods should be the least simplest form that the code requires. So if your code isn't going to add items to the dictionary, than IReadOnlyDictionary<string, object> is all you need to require.

@codingseb
Copy link
Owner

codingseb commented Mar 29, 2019

It's done in dev branch. Will be available in v : 1.3.6.0

It's IDictionary<string, object> because when you do :

x = 5

it actually put x in Variables Dictionary.
Yes I know it's not necessary the best solution and variables scoping is done the wrong way.
But it was the easy way for now.
I still have some improvements in my todo list related to variables management

@codingseb
Copy link
Owner

codingseb commented Apr 2, 2019

Version 1.3.6.0 is avaiable.

Just a comment. A object that inherit from IDictionary<string, object> can be given to ExpressionEvaluator. So All KeyValuePairs will be use as variable.
But modifications are not reported in the object because internally ExpressionEvaluator use a copy of the given Dictionary. This is linked to OptionCaseSensitiveEvaluationActive, when it's value change the entire Variables Dictionary is copied again to be case sensitive or not.

@kasajian
Copy link
Author

kasajian commented Apr 6, 2019 via email

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