Click here to Skip to main content
15,125,299 members
Articles / Programming Languages / C#
Posted 29 Aug 2006


93 bookmarked

Use Rules In Your Applications

Rate me:
Please Sign up or sign in to vote.
4.84/5 (19 votes)
29 Aug 2006CPOL2 min read
A Rules Engine class library with source code and documentation
Overview of first Use Case


This Rules Engine was formulated from my need to provide automation based on external rules. The rules were to govern how the graphical user interface (GUI) behaved in response to Rule execution. De-coupling the rules of the application enabled me to then develop the GUI independently of the Rules and to develop the Rules independently of the application. The connection between the application and the rules is a rules engine whose responsibility is the execution of the rules and notifying the application of changes to variables.

This is the original intent of this Rules Engine, it has since evolved in scope and applicability.


The original intent of this library precluded any notion of ambiguous or non-determinant rule execution. The original need required absolute determination of results since the automation of a GUI cannot resolve ambiguity. I decided to define Rules such that the Rule maker made the decision tree(s).

Rules engines that I have seen (Corticon's offering excepted) are built upon the RETE algorithm. This engine does not utilize the RETE algorithm. RETE can produce non-determinant results which can be disastrous to automation. RETE is better suited to analysis than automation.

This engine has evolved to accommodate various use cases.

Image 2

Thread-safety is integral to the engine and is implemented using the ReaderWriter lock in .NET. Rule execution based on variable changes is implemented by defining "Triggers". Events for rule execution as well as variable changes are also defined.

Using the Code

The Rules Engine is utilized by instantiating a Rule Engine object from the class. The Rules Engine can then be loaded with Rules.

Instantiating a Rules Engine and adding delegates:

Variable _oVariableEngine = new VariableEngine();
RulesEngine _oRulesEngine = new RulesEngine();
_oRulesEngine.VarEngine = _oVariableEngine;

_oRulesEngine.VariableChanging += 
    new RulesEngine.VariableChangingDelegate(_oRulesEngine_VariableChanging);
_oRulesEngine.VariableChanged +=
    new RulesEngine.VariableChangedDelegate(_oRulesEngine_VariableChanged);
_oRulesEngine.VariableAdded +=
    new RulesEngine.VariableAddedDelegate(_oRulesEngine_VariableAdded);
_oRulesEngine.RuleEntered +=
    new RulesEngine.RuleEnteredDelegate(_oRulesEngine_RuleEntered);
_oRulesEngine.RuleComplete += 
    new RulesEngine.RuleCompleteDelegate(_oRulesEngine_RuleComplete);

Rules can be defined and loaded into the engine from any source. The source code contains a Reader/Writer Visual Studio Solution as well as an XML Schema (with documentation) for using an XML file to define and persist Rules.

Links of Interest

Points of Interest

  • Type-safe collections are implemented by extending CollectionBase and using a binary search algorithm to provide high performance access to any item in the collection.
  • Variables are class objects that have overloaded operators.
  • There is an Interface that allows any object to be used as a variable. Using DataSets as variables are implemented using this methodology
  • The source code contains the complete Visual Studio Solution of Jaxlab Rules Engine, complete Visual Studio Solution for Reader/Writer class, Rule XML Schema and documentation, complete documentation of Rules Engine (HTML and CHM).
  • A Rule can contain Rules to create rule trees to organize rules and rule processing.


  • 29th August, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Jeff Bramlett
Software Developer (Senior)
United States United States

Comments and Discussions

GeneralThe License is LGPL not CPOL Pin
CyborgDE11-Jun-11 4:38
MemberCyborgDE11-Jun-11 4:38 
QuestionHow to match variables plz. help me [modified] Pin
ShyamPrasadP5-Dec-10 21:05
MemberShyamPrasadP5-Dec-10 21:05 
GeneralQuestion Pin
chazim12-Nov-10 9:20
Memberchazim12-Nov-10 9:20 
GeneralRe: Question Pin
Jeff Bramlett12-Nov-10 16:03
MemberJeff Bramlett12-Nov-10 16:03 
GeneralRe: Question Pin
terryterryd14-Apr-11 3:08
Memberterryterryd14-Apr-11 3:08 
GeneralRe: Question Pin
Jeff Bramlett12-Nov-10 16:05
MemberJeff Bramlett12-Nov-10 16:05 
QuestionHow to use loops Pin
Sumit Prakash Sharma20-Apr-09 3:17
MemberSumit Prakash Sharma20-Apr-09 3:17 
QuestionNeed Help ! Pin
rajalakshmiam17-Apr-09 0:51
Memberrajalakshmiam17-Apr-09 0:51 
GeneralBroken Links Pin
chris lambrou1-Mar-09 20:05
Memberchris lambrou1-Mar-09 20:05 
GeneralGUI for making new rules and editing the existing one Pin
Banty Nigam12-Feb-09 21:29
MemberBanty Nigam12-Feb-09 21:29 
NewsGood article Pin
Arash Aghlara2-Aug-08 23:12
MemberArash Aghlara2-Aug-08 23:12 
GeneralAuthor's Web Site Pin
vextant10-Feb-08 19:15
Membervextant10-Feb-08 19:15 
GeneralRe: Author's Web Site Pin
ARUVAL3-Mar-08 7:21
MemberARUVAL3-Mar-08 7:21 
GeneralNxBre Pin
Tim Schwallie26-Jan-07 12:03
MemberTim Schwallie26-Jan-07 12:03 
GeneralRe: NxBre Pin
Jeff Bramlett29-Jan-07 9:33
MemberJeff Bramlett29-Jan-07 9:33 
GeneralThank you, this is impressive. Pin
Grav-Vt29-Nov-06 14:48
MemberGrav-Vt29-Nov-06 14:48 
QuestionHow to create rules? Pin
victorvieira1-Nov-06 5:53
Membervictorvieira1-Nov-06 5:53 
AnswerRe: How to create rules? Pin
jeff_bramlett@hotmail.com2-Nov-06 1:40
Memberjeff_bramlett@hotmail.com2-Nov-06 1:40 
AnswerRe: How to create rules? Pin
jeff_bramlett@hotmail.com2-Nov-06 1:48
Memberjeff_bramlett@hotmail.com2-Nov-06 1:48 
QuestionReturning a String result Pin
Rob_Jurado8-Sep-06 13:49
MemberRob_Jurado8-Sep-06 13:49 
Questionlooking for a Trigger by name Pin
Rob_Jurado6-Sep-06 11:53
MemberRob_Jurado6-Sep-06 11:53 
AnswerRe: looking for a Trigger by name Pin
Jeff Bramlett6-Sep-06 15:06
MemberJeff Bramlett6-Sep-06 15:06 
GeneralNice work Pin
Rob_Jurado5-Sep-06 13:42
MemberRob_Jurado5-Sep-06 13:42 
GeneralThanks for posting Pin
jruvelIGN30-Aug-06 8:15
MemberjruvelIGN30-Aug-06 8:15 
GeneralRe: Thanks for posting Pin
Jeff Bramlett30-Aug-06 8:27
MemberJeff Bramlett30-Aug-06 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.