-
Notifications
You must be signed in to change notification settings - Fork 0
ComposingSpecifications
Craig Fowler edited this page Mar 5, 2020
·
2 revisions
Specification objects may be logically composed/combined. There are three operators to do this: And
, Or
and Not
. They are demonstrated by the following examples. Note that for brevity these examples use dynamic specification expressions. Composition works identically with instances of specification classes.
// And
var overSix = Spec.Expr<int>(x => x > 6);
var underTen = Spec.Expr<int>(x => x < 10);
var sevenEightNine = overSix.And(underTen);
// Or
var overSix = Spec.Expr<int>(x => x > 6);
var underTwo = Spec.Expr<int>(x => x < 2);
var notTwoToSix = overSix.Or(underTwo);
// Not
var overSix = Spec.Expr<int>(x => x > 6);
var sixOrLess = overSix.Not();
- Composing two specification expressions, or using
Not
with an expression, will create a new specification expression - Composing two specification functions, or a combination of an expression and a function, or using
Not
with a function will create a new specification function