<- Back to Documentation Index

Migration

Breaking: a rule now takes exactly one parameter

A rule takes exactly one RuleParameter. The previous multi-parameter support (up to 16 parameters) has been removed. When a rule needs several values, wrap them in a small struct or class and pass one RuleParameter of that type; reference the wrapper’s members in the expression.

Before (multi-parameter):

var rule = new Rule { Expression = "price > 0 && quantity > 0" };

workflow.Compile(new[]
{
    new RuleParameter("price", typeof(decimal)),
    new RuleParameter("quantity", typeof(int))
});

After (single parameter + wrapper):

public record Order(decimal Price, int Quantity);

var rule = new Rule { Expression = "order.Price > 0 && order.Quantity > 0" };

workflow.Compile(new RuleParameter("order", typeof(Order)));

Compile, Execute, ExecuteAsync, ExecuteParallel, ExecuteParallelAsync, and ExecuteBufferedAsync now take a single RuleParameter instead of a RuleParameter[]. RuleExecutingEventArgs.Parameters has been renamed to Parameter (a single RuleParameter).


From 0.x to 1.x

Breaking Changes

0.x 1.x Migration
Rule.Id auto-generated Rule.Id still auto-generated No change
One parameter per rule One parameter per rule Wrap multiple values in a struct/class
workflow.Rules mutable after compile Immutable after Compile() Add rules before compile
No ValidateSemantics Static ValidateSemantics overloads Use for input validation
AssemblyReferenceProvider basic Whitelist + hardening Review whitelist

Wrapping Multiple Values

A rule takes exactly one parameter. Wrap multiple values in a struct or class and reference its members in the expression:

public record Input(int A, int B);

var rule = new Rule { Expression = "input.A > input.B" };
var param = new RuleParameter("input", typeof(Input), new Input(1, 2));

Workflow Immutability

Before (0.x):

workflow.Compile(parameters);
workflow.Rules.Add(newRule);  // Was allowed
workflow.Compile(parameters); // Re-compile

After (1.x):

workflow.Rules.Add(newRule);
workflow.Compile(parameters);  // Locks Rules
// workflow.Rules.Add(another); // NotSupportedException

Static ValidateSemantics

New in 1.x — validate user input without creating a Rule:

// Validate API input before storing
Rule.ValidateSemantics(userExpression, typeof(Customer), "customer");

From Microsoft.RulesEngine

Key Changes

RulesEngine This Engine
new RulesEngine.RulesEngine() new Workflow()
engine.ExecuteAllRulesAsync() workflow.Execute() or workflow.ExecuteParallelAsync()
Rule.Expression Rule.Expression (same)
Rule.RuleName Rule.Description
Rule.SuccessEvent Use Rule.Action
Rule.ErrorMessage Not needed — exceptions on failure
Multi-parameter One parameter — wrap multiple values in a struct/class
DynamicInvoke Typed delegates

Example Migration

Before (RulesEngine)

var rules = new[] {
    new Rule {
        RuleName = "CheckAge",
        Expression = "input1.Age >= 18"
    }
};

var engine = new RulesEngine.RulesEngine(rules);
var result = await engine.ExecuteAllRulesAsync("CheckAge", customer);

After (This Engine)

var rule = new Rule {
    Description = "CheckAge",
    Expression = "customer.Age >= 18"
};

var workflow = new Workflow {
    Rules = new List<Rule> { rule }
};

var compileParam = new RuleParameter("customer", typeof(Customer));
var executeParam = new RuleParameter("customer", typeof(Customer), customer);

workflow.Validate();
workflow.Compile(compileParam);

var results = workflow.Execute(executeParam);

Tip: You can compile without a value if you separate compilation from execution:

// Compile at startup with a null value — the type is what matters
workflow.Compile(new RuleParameter("customer", typeof(Customer))); // value defaults to null

// Execute later with a real instance
var results = workflow.Execute(new RuleParameter("customer", typeof(Customer), customer));

Breaking Changes

  1. No built-in error message — Handle exceptions in caller
  2. Expression uses parameter name — Not input1, use declared name
  3. Compile once — Call Compile() before executing

Benefits of Migrating

Metric Improvement
Execution speed 10-100x faster (no System.Linq.Dynamic.Core)
Memory Lower allocation
Thread safety Immutable rules, no locks
Validation Catch errors before runtime
Async Native async/await support
Single parameter One typed parameter — wrap multiple values in a struct/class

License

MIT License — same permissive terms as before.


Back to top

MIT License. Built with Roslyn + Typed Delegates.