Path: redb-route/redb.Route/Predicates/BetweenPredicate.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/BetweenPredicate.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Predicates;
///
/// Predicate that checks whether an expression result falls between two values (inclusive).
///
public class BetweenPredicate : IPredicate
{
private readonly IExpression _expression;
private readonly IComparable _low;
private readonly IComparable _high;
///
/// Initializes a new instance with the specified expression and boundary values.
///
/// The expression to evaluate.
/// The lower bound (inclusive, must implement ).
/// The upper bound (inclusive, must implement ).
public BetweenPredicate(IExpression expression, object low, object high)
{
_expression = expression;
_low = (IComparable)low;
_high = (IComparable)high;
}
///
public bool Matches(IExchange exchange)
{
var result = _expression.Evaluate(exchange);
return result?.CompareTo(_low) >= 0 && result?.CompareTo(_high) <= 0;
}
///
public Task MatchesAsync(IExchange exchange)
=> Task.FromResult(Matches(exchange));
}