[ACCEPTED]-Looking for simple rules-engine library in .NET-rule-engine

Accepted answer
Score: 46

Agreeing with will I would say use something 18 from the workflow engine family although 17 not workflow. Examine System.Workflow.Activities.Rules Namespace a little 16 bit - it's supported in .Net 3, and built 15 into .Net3.5. You have everything in hand 14 for free to use like you mentioned :

  • RuleCondition 13 for conditions , RuleAction for actions 12

  • standardized format for describing metacode 11 (CodeDom - CodeExpressions)

  • you can plugin 10 any kind of complexity into that (to tell 9 the truth except Linq and lambdas and 8 so extension methods of some kind) via TypeProviders

  • there's 7 a builtin editor for rule editing with intellisense

  • as 6 the rule is serializable it can be easily 5 persisted

  • if you meant to use the rules over a database scheme then via typeprovider it can be implemented too

For a starter : Using rules outside of a workflow

Ps.: we're using 4 it extensively and there're much more in 3 that namespace than you ever imagine -> a 2 complete meta algorithm language

And the 1 most important : it's easy to use - really

Score: 18

Here is a class I have used in the past. It 5 evaluates strings just like eval() does 4 in Javascript.

String result = ExpressionEvaluator.EvaluateToString("(2+5) < 8");

All you need to do is construct 3 a string to be evaluated from your business 2 objects and this will take care of all the 1 complicated nested logic etc.

using System;
using System.CodeDom.Compiler;
using System.Globalization;
using System.Reflection;
using Microsoft.JScript;

namespace Common.Rule
  internal static class ExpressionEvaluator
    #region static members
    private static object _evaluator = GetEvaluator();
    private static Type _evaluatorType;
    private const string _evaluatorSourceCode =
        @"package Evaluator
               class Evaluator
                  public function Eval(expr : String) : String 
                     return eval(expr); 


    #region static methods
    private static object GetEvaluator()
      CompilerParameters parameters;
      parameters = new CompilerParameters();
      parameters.GenerateInMemory = true;

      JScriptCodeProvider jp = new JScriptCodeProvider();
      CompilerResults results = jp.CompileAssemblyFromSource(parameters, _evaluatorSourceCode);

      Assembly assembly = results.CompiledAssembly;
      _evaluatorType = assembly.GetType("Evaluator.Evaluator");

      return Activator.CreateInstance(_evaluatorType);

    /// <summary>
    /// Executes the passed JScript Statement and returns the string representation of the result
    /// </summary>
    /// <param name="statement">A JScript statement to execute</param>
    /// <returns>The string representation of the result of evaluating the passed statement</returns>
    public static string EvaluateToString(string statement)
      object o = EvaluateToObject(statement);
      return o.ToString();

    /// <summary>
    /// Executes the passed JScript Statement and returns the result
    /// </summary>
    /// <param name="statement">A JScript statement to execute</param>
    /// <returns>The result of evaluating the passed statement</returns>
    public static object EvaluateToObject(string statement)
      lock (_evaluator)
        return _evaluatorType.InvokeMember(
                    new object[] { statement },
Score: 8

None of the open sourced .NET rules-engine 18 have support for storing rules in the database. The 17 only ones that stored the rules in a database 16 are commercial. I've created some UIs for 15 custom rule engines that run off the database, but 14 this can be non-trivial to implement. That's 13 usually the main reason you won't see that 12 feature for free.

As far as I know, none 11 of them will meet all of your criteria, but 10 here is a list of the ones I know of:

Simplest 9 one is SRE

One with rule management UI is 8 NxBRE

Drools.NET uses JBOSS rules

I personally 7 haven't used any of them, because all of 6 the projects I worked with never wanted 5 to use something built in-house. Most business 4 think that this is pretty easy to do, but 3 end up wasting too much time coding and 2 implementing it. This is one of those areas 1 that the Not Invented Here Syndrome (NIH) rules.

Score: 7

Well, since logical expression are just 2 a subset of mathematical expression, you 1 may want to try NCalc - Mathematical Expressions Evaluator for .NET over on CodePlex.

Score: 5

The official MS solution for this is Windows Workflow. Although 4 I wouldn't call it "simple", it 3 meets all of your specifications (which 2 would require an extensive framework to 1 meet, anyhow).

Score: 4

I've used this http://www.codeproject.com/KB/recipes/Flee.aspx with success in the past. Give 1 it a try.

Score: 3

Windows Workflow Foundation does give you 9 a free forward chaining inference engine. And 8 you can use it without the workflow part. Creating 7 and Editing rules is ok for developers.

If 6 you want to have non-programmers edit and 5 maintain the rules you can try out the Rule Manager.

The 4 Rule Manager will generate a working visual 3 studio solution for you. That should get 2 you started rather quickly. Just click on 1 File \ Export and selecte the WFRules format.

Score: 2

You can take a look at our product as well 6 at http://www.FlexRule.com

FlexRule is a Business Rule Engine framework 5 with support for three engines; Procedural 4 engine, Inference engine and RuleFlow engine. Its 3 inference engine is a forward chaining inference 2 that uses enhanced implementation of Rete 1 Algorithm.

Score: 1

I would look at Windows Workflow. Rules 5 engines and workflow tend to start simple 4 and get progressively more complex. Something 3 like Windows Workflow Foundation is not 2 too difficult to start with and provides 1 room for growth. Here is a post that shows it's not too difficult to get a simple workflow engine going.

Score: 1

Maybe check out SmartRules. Its not free, but the 4 interface looks simple enough.

Only know 3 about it because I've used the SmartCode 2 codegen utility from there before.

Here is 1 an example rule from the Website:


If (Customer.Age > 50 && Customer.Status == Status.Active) {
policy.SetDiscount(true, 10%);

After (with Smart Rules)
If Customer is older than 50 and
the Customer Status is Active Then
Apply 10 % of Discount
Score: 1

You can use a RuEn, an simple open source 1 attribute based Rule Engine created by me:


Score: 1

Have a look at Logician: tutorial/overview on CodeProject

Project: page/source on 1 SourceForge

Score: 1

Try out http://rulesengine.codeplex.com/

It's a C# Open-Source rules engine 1 that works with Expression trees.

Score: 0

Depending on what you are trying to do using 8 Lambda expressions (and expression trees) can 7 work for this concept. Essentially, you 6 provide an expression as a string that is 5 then compiled on the fly into a lambda expression/expression 4 tree, which you can then execute (evaluate). It's 3 not simple to understand at first, but once 2 you do it's extremely powerful and fairly 1 simple to set up.

Score: 0

It's not free, as you can't easily untangle 8 it from its BizTalk parentage, but the Business 7 Rules Engine components of BizTalk are a 6 separate entity from the core BizTalk engine 5 itself, and comprise a very powerful rules 4 engine that includes a rules / policy based 3 GUI. If there was a free version of this 2 it would fit your requirements (buying BizTalk 1 just for the BRE wouldn't really work commercially.)

More Related questions