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!