Analysis formulas in .NET.

I am trying to parse a formula in C #, for example

"5*3 + 2" "(3*4 - 2)/5" 

Is it possible to do this in C # or scripts such as VBScript, JavaScript (which will be called in a C # program).

+4
source share
3 answers

Here is the trick I used before to do this in C # to use the JScript.NET eval function. You will find the full code in your answer to this question . It does not rely on a scripting language such as VBScript or JavaScript, it is pure .NET, and the implementation I use generates a JScript.NET assembly on the fly from C # code, so there is no need to mix languages ​​in your solution.

+2
source

I had a lot of experience with Flee , the C # library that evaluates expressions such as those described by you. You can evaluate expressions as strongly typed operators, so if you need an integer, for example, "(1 + 2) * 5" would be nice, but there would be no "hello world".

You can even connect certain variables or functions. Page The Running Page is a great starting point.

+4
source

I have successfully used the Microsoft Dynamic Linq sample to dynamically formulate expressions that use types under the System.Linq.Expressions namespace . This works very well for me and allows you to use the more natural C # syntax instead of the default ActiveReports expression.

+1
source

Source: https://habr.com/ru/post/1306992/


All Articles