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

Getting evaluated expression as string #48

Open
mkalinski93 opened this issue Apr 8, 2022 · 1 comment
Open

Getting evaluated expression as string #48

mkalinski93 opened this issue Apr 8, 2022 · 1 comment

Comments

@mkalinski93
Copy link

mkalinski93 commented Apr 8, 2022

Hello,

I just wanted to get to know if it is possible to get the evaluated expression as a string.

ValueA = 10
ValueB = 15

For example: [ValueA] + [ValueB]
Results in: "10 + 15"

This can be really helpful if you want to track down the calculation to see what happened there.

@petli
Copy link
Contributor

petli commented Apr 14, 2022

There is no ready-made function for it, but you can achieve this by implementing a https://github.com/ncalc/ncalc/blob/master/src/NCalc/Domain/LogicalExpressionVisitor.cs that does it. You could take most of https://github.com/ncalc/ncalc/blob/master/src/NCalc/Domain/SerializationVisitor.cs but modify Visit(Identifier) to evaluate the parameter and add that to the string instead. The parameter evaluation can be based on the corresponding code in the evaluation visitor: https://github.com/ncalc/ncalc/blob/master/src/NCalc/Domain/EvaluationVisitor.cs#L663-L700

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

3 participants