ExpressionEvaluator
ExpressionEvaluator copied to clipboard
Escaping variable names
Hi Seb! First of all I'd like to say this library is quite a marvel compared to the alternatives we have in the dotnet world!. Keep up the good work!!
This is not an issue per say, but i'm wondering if there is a way to escape the variables names in expressions.
The goal here would be to allow hyphen-case variables to be properly identified by the parser for example i'd like to be able to evaluate expressions like this :
var exp = "net-pv / Total::net-pv"
where net-pv and Total::net-pv are both variables.
If the functionality does not exist , a quick win might be to use string literals to help distinguish variable names in the expression
var exp = $"{net-pv}/{Total::net-pv}"
Hello @cantacuzene. I am sorry it's hard for me to give fast answer for now because I am in vacations and I only have my smartphone. I don't know if I fully understand your question but the answer is that there is no integrated solution to escape variables. But by inheritance you could define your own syntax for this by modifying the parsing process. For a first example for your case look here
You can find some documentation on the wiki Here
An other way to do it could be with "on the fly" function. Something like getVar(net-pv) For the doc look here.
Hi @codingseb this was exactly what I was looking for. I guess I should have digged further into the manual, I totally missed this parsing customization section ... I am not a big fan of inheritence but it'll work just fine :) Thanks a lot for your reply!
I reopen this because it could be useful for others.