Path: redb-route/redb.Route/Predicates/AndPredicate.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/AndPredicate.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Predicates;
///
/// Predicate that performs a logical AND between an expression and another predicate.
/// Returns true only when both the expression evaluates to true and the predicate matches.
///
public class AndPredicate : IPredicate
{
private readonly IExpression _expression;
private readonly IPredicate _predicate;
///
/// Initializes a new instance combining an expression and a predicate with logical AND.
///
/// The expression to evaluate (left-hand side of AND).
/// The predicate to check (right-hand side of AND).
public AndPredicate(IExpression expression, IPredicate predicate)
{
_expression = expression;
_predicate = predicate;
}
///
public bool Matches(IExchange exchange)
{
bool expressionResult = _expression.Evaluate(exchange);
return expressionResult && _predicate.Matches(exchange);
}
///
public async Task MatchesAsync(IExchange exchange)
{
bool expressionResult = _expression.Evaluate(exchange);
return expressionResult && await _predicate.MatchesAsync(exchange).ConfigureAwait(false);
}
}