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.Ruleis 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
WhenandThensections only once. If you specify them multiple times, all conditions would still be combined into a single set usingandgroup. 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
AandB, and if both those facts match, then bothXandYmethods 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
AandBwith anOR, you could do it like below. Here the rule will fire if((A OR B) AND C):