Path: redb-route/redb.Route/Predicates/NotPredicate.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Predicates/NotPredicate.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Predicates;
///
/// Predicate that negates the boolean result of an expression (logical NOT).
///
public class NotPredicate : IPredicate
{
private readonly IExpression _expression;
///
/// Initializes a new instance with the expression to negate.
///
/// The expression whose boolean result will be inverted.
public NotPredicate(IExpression expression)
{
_expression = expression ?? throw new ArgumentNullException(nameof(expression));
}
///
public bool Matches(IExchange exchange)
{
return !_expression.Evaluate(exchange);
}
///
public Task MatchesAsync(IExchange exchange)
{
return Task.Run(() =>
{
return !_expression.Evaluate(exchange);
});
}
}