I need to parse complex expresion from string to bool.
It can only contain:
* boolean values (true/false),
* parenthesis,
* AND/OR operands (&&, ||)
Eg:
bool.Parse("((true || false) && (false || false)) || (true || false)"
Any idea how to achieve this?
Here's a cunning evaluator class that gives you the JScript.NET Eval function within C# code:
You just then call Evaluator.EvaluateToBool(string). Lifted from an existing project, so you may want to tweak!
The string you described is valid C# code, so if you can interpret it at runtime you're done. In many languages this is a built in function. In C# it is not, but you can use a 3rd party library such as this runtime C# interpreter
The standard method is to: