When organizing rules for NRules, is it necessary to only have 1 When/Then group in a file?
I have one rule that looks at 3 conditions (fact matches), is flagA = false, inputA = one of a list of values, and inputB = a single value. When all true, set flagA to true. I got that one working,then wanted to add the second rule.
The second rule is when flagA is false and flagB is true then set flagA to true.
Do these two rules need to be in separate .cs files or can they be together in one.
I looked at the ".Or" option, but I am not good enough with fluent to figure out what it is doing.
Thanks for your help, Toom
In NRules an instance of a class that inherits from
NRules.Fluent.Dsl.Rule
is one rule. You can put multiple rule classes in one .cs file or different files, it does not matter - each class is still a separate rule.In that rule class, you normally would specify
When
andThen
sections only once. If you specify them multiple times, all conditions would still be combined into a single set usingand
group. Actions would also be merged into a single set.So:
is exactly the same as
In other words, both examples above create just a single rule that matches both
A
andB
, and if both those facts match, then bothX
andY
methods are executed.If you want that to be two independent rules, then put those different When/Then sections into different rule classes.
UPDATE: If you wanted to connect conditions
A
andB
with anOR
, you could do it like below. Here the rule will fire if((A OR B) AND C)
: