Does anyone know of a good .NET library rules library (ideally open-source)? I need something that can do nested logic expressions, e.g., (A AND B) AND (B OR C OR D). I need to do comparisons of object properties, e.g., A.P1 AND B.P1. (Ideally, I could compare any property -- A.P1 AND B.P2).
It should store the rules in a database (I've got a lot of simple configurable logic). And it should have a rule creation/management API. The management tool would have to inspect the instances to determine which properties are available and which constraints exist.
Thanks!
Oh, one more thing. As a rules-engine, I need to include the concept of Actions (Commands). These are what execute when the expression returns:
If (expression.Evaluation) { actions.Execute(); }
So I see a rule as something like:
class Rule { Expression Exp; Actions[] Actions; Run() { if(Exp.Evaluate()) { foreach(action in Actions) { action.Execute(); } } } }
The Rules Engine is a . NET C# project that validates business logic by defining a multiple rules for your data classes.
Steps to implement Rule Engine Design patternWrite all rules in one method using if-then-else conditional statements. Step 2: Create classes for each rule. Create separate classes for each rule. Add a ShouldRun() method in each class file to determine whether the business rule has to be executed or not.
For software developers, a rule engine is useful only if it liberates them from expressing the rule in the code. In order to avoid this pitfall, it is commonly accepted that we should use rule engines only if appropriate, or not use them at all. Over the past decades, that has become a self-fulfilling prophecy.
A rule engine combines a set of facts that are inserted in to the system with its own Rule Set to reach a conclusion of triggering one or several actions. These rules typically describe in a declarative manner the business logic which needs to be implemented in our environment (which we assume rarely changes).
Agreeing with will I would say use something from the workflow engine family although not workflow. Examine System.Workflow.Activities.Rules Namespace a little bit - it's supported in .Net 3, and built into .Net3.5. You have everything in hand for free to use like you mentioned :
RuleCondition for conditions , RuleAction for actions
standardized format for describing metacode (CodeDom - CodeExpressions)
you can plugin any kind of complexity into that (to tell the truth except Linq and lambdas and so extension methods of some kind) via TypeProviders
there's a builtin editor for rule editing with intellisense
as the rule is serializable it can be easily persisted
For a starter : Using rules outside of a workflow
Ps.: we're using it extensively and there're much more in that namespace than you ever imagine -> a complete meta algorithm language
And the most important : it's easy to use - really
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With