ReSettings reference
ReSettings configures a RulesEngine instance. Pass it to the constructor:
var settings = new ReSettings
{
CustomTypes = new[] { typeof(MyHelpers) },
NestedRuleExecutionMode = NestedRuleExecutionMode.Performance
};
var engine = new RulesEngine.RulesEngine(workflows, settings);
The engine takes a copy of the settings when it is constructed. Changing your ReSettings object afterwards does not affect the engine. (The engine itself may add input types to its own copy of CustomTypes when AutoRegisterInputType is on.)
Settings
The defaults below are the values of new ReSettings().
| Property | Type | Default | Description |
|---|---|---|---|
CustomTypes |
Type[] |
null |
Types whose methods and static members expressions may call. See the type security model. |
CustomActions |
Dictionary<string, Func<ActionBase>> |
null |
Your own actions, by name. Names must not clash with the built-in OutputExpression and EvaluateRule. See Actions. |
EnableExceptionAsErrorMessage |
bool |
true |
Report rule problems as a failed result with an ExceptionMessage. When false, the exception is thrown. See Error handling. |
IgnoreException |
bool |
false |
Leave ExceptionMessage empty for rule errors and do not rethrow action exceptions. |
EnableFormattedErrorMessage |
bool |
true |
Replace $(...) placeholders in Rule.ErrorMessage. |
EnableScopedParams |
bool |
true |
Enable GlobalParams and LocalParams. When false, rules that use them fail to parse. |
IsExpressionCaseSensitive |
bool |
false |
Whether identifiers, members and input names in expressions are case-sensitive. |
AutoRegisterInputType |
bool |
true |
Register the type of every input (including generic arguments, array element types and nullable underlying types) so methods on it can be called. |
EnableAssemblyScanning |
bool |
true |
Scan loaded assemblies for types marked [DynamicLinqType] so they can be used in expressions. Set to false to use only CustomTypes and input types, which also avoids the scan cost. |
NestedRuleExecutionMode |
NestedRuleExecutionMode |
All |
All evaluates every child rule; Performance stops as soon as the parent's result is decided. |
CacheConfig |
MemCacheConfig |
null (the engine uses SizeLimit = 1000) |
Size of each internal cache, counted in entries. SizeLimit <= 0 disables the compiled-expression cache. See Caching. |
UseFastExpressionCompiler |
bool |
false |
Compile expressions with FastExpressionCompiler instead of Expression.Compile(). |
EnableExceptionAsErrorMessageForRuleExpressionParsing |
bool |
true |
When false, an expression that cannot be parsed is silently replaced by a default value instead of an error. |
AutoExecuteActions |
bool |
true |
Run each rule's OnSuccess or OnFailure action inside ExecuteAllRulesAsync. When false, run them yourself with ExecuteActionWorkflowAsync. |
EnableParallelRuleCompilation |
bool |
false |
Compile the rules of a workflow in parallel. Used only for workflows with 32 or more enabled rules, and ignored when UseFastExpressionCompiler is true. |
NestedRuleExecutionMode
| Value | Description |
|---|---|
All |
Executes every nested rule. |
Performance |
Skips nested rules whose execution cannot change the parent's result. ChildResults then contains only the evaluated children. |
Choosing settings
| Goal | Settings |
|---|---|
| Fail fast in tests and CI | EnableExceptionAsErrorMessage = false |
| Never show rule error details to users | IgnoreException = true (keep EnableExceptionAsErrorMessage = true) |
| Smaller, explicit set of callable types | EnableAssemblyScanning = false and list the types you need in CustomTypes |
| Fewer evaluations for large OR rules | NestedRuleExecutionMode = Performance |
| Lower warm-up time for thousands of rules | EnableParallelRuleCompilation = true (leave UseFastExpressionCompiler off) |
| Evaluate first, run actions selectively | AutoExecuteActions = false |