The MicroExpressionEvaluator is a highly efficient .NET class library, optimized for parsing and evaluating complex nested conditional logic expressions (microexpressions) in C#. Tailored for real-time scenarios, it offers unparalleled performance with minimal CPU usage, ideal for dynamic rule evaluation in various applications like financial modeling, gaming logic, and more.
- Rapid Evaluation: Executes complex logic expressions extremely fast.
- Type Support: Handles expressions involving
decimal
,boolean
, andstring
. - Operator Versatility: Supports logical (
||
,&&
,!
, etc.) and comparison (==
,!=
,<
,>
, etc.) operators. - Nested and Grouped Expressions: Efficiently simplifies and evaluates expressions with multiple nested and logical groups.
- Security and Independence: Operates without regular expressions or scripting engines, reducing security risks and dependencies.
Benchmarked to outperform traditional methods and tools, the MicroExpressionEvaluator avoids slow methods like regular expressions (about 100x) and scripting engines (around 1000x), making it a superior choice for applications requiring high-speed logic processing.
Simple and straightforward:
bool result = MicroEx.Evaluate("your_expression_here");
Replace your_expression_here
with your logic expression.
Input --> Output
7 > -7 --> Returns: true
true == true != false --> Returns: true
(true || true) && false --> Returns: false
!true == !(true || false) --> Returns: true
("text123" == "text123") && (7,00000 < 7,00001) --> Returns: true
10000000000,00000000000 < 10000000000,00000000001 --> Returns: true
(false != true) && ((true || false) || (true == false)) --> Returns: true
(false || (true == (false || (true == (false || true))))) --> Returns: true
(true --> Throws (expected) exception: "Invalid input! ) expected."
-7 && 7 --> Throws (expected) exception: "Invalid input! Operator can only be applied to operands of type 'bool'."
"text123" == true --> Throws (expected) exception: "Invalid input! Operator can only be applied to operands of type 'bool'."
Perfect for systems requiring constant rule evaluation under varying conditions, such as in automated decision-making, system monitoring, or configuration validation.
Other projects like NCalc, Jint, NLua, and Roslyn were evaluated but found to be slower or less suitable for the specific needs.
Plans to expand capabilities include support for mathematical operations and additional operators (+
, -
, *
, /
, ^
, %
).
Your contributions, issues, and suggestions are welcome to enhance this project further.
Please refer to the provided license information for usage guidelines.
We welcome your feedback and hope you find the MicroExpressionEvaluator invaluable in your projects!