Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

pragmatrix/Rulez

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Rulez

Rulez is the simplest possible Rule engine I can imagine for .NET.

##Facts and Rules

A Rule is specified by a .NET delegate (Action), that uses Facts for its computation.

To specify a Rule, use

Rule.activate(Action);

A Fact represents a mutable value. To create a Fact, use either

var integerValue = Fact.of(10);

or

var myInt = Fact.of<int>();

To change a Fact, assign a value to it:

myInt.Value = 4;

A Rule is evaluated in the context of the current Dispatcher.

While a Rule is evaluated, all Facts that are accessed are tracked.

A Rule has a lifetime. When it is active, it is automatically reevaluated as soon one of its referred Facts change. To deactivate a Rule call Dispose() on the return value of Rule.activate().

Rules may change other Facts.

For example, the following code keeps the result variable always at two times the input variable:

var input = Fact.of(0);
int result = 0;
Rule.activate(() => result = input.Value*2);

Note that the evaluation is deferred through the .NET Dispatcher. This means that the evaluation results may not be updated immediately.

##RuleSets

A RuleSet combines multiple Rules together.

To create a custom RuleSet, create a class that derives from RuleSet.

To add a Rule to your RuleSet, create a method that contains the Rule logic and attribute it with [Rule].

Any [Rule] attributed method in a RuleSet derived class is automatically activated as a Rule when the RuleSet class is instantiated.

To deactivate the RuleSet call its Dispose() method.

TBD: Examples

About

Rulez, a minimalistic rule evaluation engine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages