c# - How to do optimal write rule definition in NRules -


the code of nrules simplerule define following rule:

public class preferredcustomerdiscountrule : rule {     public override void define()     {         customer customer = null;         ienumerable<order> orders = null;          when()             .match<customer>(() => customer, c => c.ispreferred)             .collect<order>(() => orders,                 o => o.customer == customer,                 o => o.isopen,                 o => !o.isdiscounted);          then()             .do(ctx => applydiscount(orders, 10.0))             .do(ctx => logorders(orders))             .do(ctx => orders.tolist().foreach(ctx.update));     }         ... } 

i wondering why conditions seperate pareameters in stead of using && operator i.e. following have same effect?

public class preferredcustomerdiscountrule : rule {     public override void define()     {         customer customer = null;         ienumerable<order> orders = null;          when()             .match<customer>(() => customer, c => c.ispreferred)             .collect<order>(() => orders,                 o => o.customer == customer && o.isopen && !o.isdiscounted);          then()             .do(ctx => applydiscount(orders, 10.0))             .do(ctx => logorders(orders))             .do(ctx => orders.tolist().foreach(ctx.update));     }         ... } 

the 2 definitions should same thing. collect method expects array of expression<func<t, bool>>. first 1 splits 3 separate conditions, while second uses 1 condition (and-combined).

i think matter of taste, 1 prefer. first 1 cleared conditions relevant , can remove or add conditions (via commenting //).


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -