3 ms·
I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is: https://github.com/Rajeev-K/formu
by rajeev-k 7y ago
I needed the ability to safely execute formulas in my .NET app. My solution was to write a parser and interpreter. Here it is:
https://github.com/Rajeev-K/formula-parser https://github.com/Rajeev-K/formula-parser
- smt88 7y agoYou can do this already with DataTables, which is basically an in-memory Excel spreadsheet. Bonus is that it also supports Excel functions, and it’s completely safe/sandboxed code.
- ftcHn 7y agoe.g. https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.data.data...
- herman_toothrot 7y agoI've used FLEE for this. Compiles down to IL so it's fast, you can define your own functions, etc. https://github.com/mparlak/Flee/wiki/Getting-Started https://github.com/mparlak/Flee/wiki/Getting-Started
- senthil_rajasek 7y agoDo you have examples of the types of "formulas" that you wanted to execute? Also, how would one execute said formula?
- rajeev-k 7y agoAny valid Visual Basic.NET expression is supported. Here are some examples: (latestquote - previousquote) / previousquote iif(isonlineorder, "Online", "Retail") FirstName & " " & LastName iif(IsNothing(Amount), "Amount missing", Format(Amount, "c2")) "Q" & ((OrderDate.Month - 1) \ 3 + 1) MonthName(DatePart(DateInterval.Month, Today), false) DateAdd(DateInterval.Day, 1, Today) See this file for example of usage: https://github.com/Rajeev-K/formula-parser/blob/master/src/Repl.cs https://github.com/Rajeev-K/formula-parser/blob/master/src/R...