I give possibility to user to input strings with unique keys that represent one-line c# complex operator (one line of code like ‘2 + (a – (x && y ? 1 : 7))‘. Operator can use Nullable<bool> and Nullable<double> variables.
At start I have Dictionary<string, object> of pre-defined values.
User can use this variables and standart c# operators: +, -, *, /, &&, ||, !, (), >, >=, <, <=, ==, !=, ?a:b, ??.
I need to reuse c# operators priority mechanism and compilation errors, warnings and messages (that goes to output after compilation)
- how to compile input string and get error messages?
- how to predefine variables that used in string, before compilation (generate code like
var x = new Nullable<bool>(true);or something other)? - is it possible to get error messages in russian language?
- can I store result of compilation for perfomance improvement (function will called multiple times later)?
Typically, you’d use an expression parser, such as NCalc, to do this. They often have an API that would be fairly easy to adapt to your requirements.
This would likely be the most difficult of your requirements, if using an existing library. However, NCalc or one of the other open sourced expression library parsers could be modified to provide Russian error messages.