Not

Feature Is supported
Null safe
Validation
EF Core
EF 6

Info

Logical NOT Specification implementation.

Usage

var spec = Specification
    .Empty<string>();
var negation = spec.Not();
    
// Empty
spec.IsSatisfiedBy("");    // true
spec.IsSatisfiedBy("lorem ipsum");    // false

// NOT empty
negation.IsSatisfiedBy("");    // false
negation.IsSatisfiedBy("lorem ipsum");    // true

Multiple negation ways

Below all examples, generate the same result.

Specification
    .NotNull<string>()
    .And()
    .NotEmail();

Specification
    .NotNull<string>()
    .And(Specification
        .Email()
        .Not());

Specification
    .NotNull<string>()
    .AndNot()
    .Email();

Negatable interfaces

All Specifications can be negated by NotSpecification<T>. Then result of specification is simple logical negation.
Sometimes, when special negation hadling is needed (for example - validation and different error message for negation), there is couple of special interfaces for negation, in FluentSpecification.Abstractions package.
Every NegatableSpecification interface is similar to normal Specification interface.
Below example describes how it works.

// ExpressionSpecification NOT implement INegatableValidationSpecification
var expSpec = Specification.Expression<bool>(b => b);

SpecificationResult result;
// return false with error: Specification doesn't meet expression: [b => b]
expSpec.IsSatisfiedBy(false, out result);
// return false without error message
expSpec.Not().IsSatisfiedBy(true, out result);

// NullSpecification implements INegatableValidationSpecification
var nullSpec = Specification.Null<string>();

// return false with error: Object is not null
nullSpec.IsSatisfiedBy("", out result);
// return false with error: Object is null
nullSpec.Not().IsSatisfiedBy(null, out result);
GitHub