My favorites | Sign in
Project Logo
                
Feeds:
People details
Project owners:
  jnewman30

Simple Rules

A simple rules engine which can operate on individual objects or more complex hierarchies of objects. Rules are classified currently by the type they operate on and are indexed by name. The central principle behind the engine is creating Lamda Expressions from method arguments to define rules in a way that will hopefully get easier to read as the project evolves.
Delegates and lambdas can be used to make it even easier to read, for example, the arguments below:
Employee.Rules
    .Add( "Terminate all hourly employees" )
    .When( Employee.is_hourly )
    .And( Employee.is_active )
    .Then( Employee.terminate );
Employee.is_active is actually a static expression property as follows:
public static Expression<Func<Employee, bool>> is_salary
{
    get { return e => e.PayType == PayType.Salary; }
}
These need to be constructed within your own domain and rely on C# method-group capability for easier readability. Furthermore if your domain objects are defined as partial you can split your data and expression properties into two separate files for readability and so that they are only visible in the area of the domain where applicable.
.Add( "Put the order on hold if it is over weight" )
    .When(o => o.CalculatedWeight > o.UpperWeightLimit )
    .Then(o => o.Status = OrderStatus.OnHold)
    .Else(o => o.Status = OrderStatus.ReadyToShip);
could become:
.Add( "Put the order on hold if it is over weight" )
    .When( load_is_too_heavy )
    .Then( place_order_on_hold )
    .Else( mark_order_ready_to_ship );








Hosted by Google Code