The code of NRules SimpleRule define the 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 am wondering why the conditions are seperate pareameters in stead of just using && operator i.e. will the following have the 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));
}
...
}