Path: redb-route/redb.Route/Expressions/Expression.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/Expressions/Expression.cs
----
using redb.Route.Abstractions;
using redb.Route.Predicates;
namespace redb.Route.Expressions;
///
/// Abstract base class for expressions that implements the interface.
/// Provides a standard set of predicate factory methods for building routing conditions.
///
public abstract class Expression : IExpression
{
///
public abstract T Evaluate(IExchange exchange);
///
public abstract void SetValue(IExchange exchange, object value);
/// Creates a predicate that checks whether the expression value equals the specified value.
/// The value to compare against.
/// An representing the equality check.
public IPredicate isEqualTo(object value) => new EqualsPredicate(this, value);
/// Creates a predicate that checks whether the expression value is greater than the specified value.
/// The value to compare against.
/// An representing the greater-than check.
public IPredicate isGreaterThan(object value) => new GreaterThanPredicate(this, value);
/// Creates a predicate that checks whether the expression value is less than the specified value.
/// The value to compare against.
/// An representing the less-than check.
public IPredicate isLessThan(object value) => new LessThanPredicate(this, value);
/// Creates a predicate that checks whether the expression value is greater than or equal to the specified value.
/// The value to compare against.
/// An representing the greater-than-or-equal check.
public IPredicate isGreaterThanOrEqualTo(object value) => new GreaterThanOrEqualPredicate(this, value);
/// Creates a predicate that checks whether the expression value is less than or equal to the specified value.
/// The value to compare against.
/// An representing the less-than-or-equal check.
public IPredicate isLessThanOrEqualTo(object value) => new LessThanOrEqualPredicate(this, value);
/// Creates a predicate that checks whether the expression value falls between two boundaries (inclusive).
/// The lower boundary.
/// The upper boundary.
/// An representing the between check.
public IPredicate isBetween(object low, object high) => new BetweenPredicate(this, low, high);
/// Creates a predicate that checks whether the expression value contains the specified value (for strings/collections).
/// The value to search for.
/// An representing the contains check.
public IPredicate contains(object value) => new ContainsPredicate(this, value);
/// Creates a predicate that checks whether the expression value starts with the specified value.
/// The prefix value to check.
/// An representing the starts-with check.
public IPredicate startsWith(object value) => new StartsWithPredicate(this, value);
/// Creates a predicate that checks whether the expression value ends with the specified value.
/// The suffix value to check.
/// An representing the ends-with check.
public IPredicate endsWith(object value) => new EndsWithPredicate(this, value);
/// Creates a predicate that checks whether the expression value matches the specified regular expression pattern.
/// The regular expression pattern.
/// An representing the regex match check.
public IPredicate regex(string pattern) => new RegexPredicate(this, pattern);
/// Creates a predicate that checks whether the expression value is contained in the specified set of values.
/// The set of values to check against.
/// An representing the membership check.
public IPredicate In(params object[] values) => new InPredicate(this, values);
/// Creates a predicate that checks whether the expression value does not equal the specified value.
/// The value to compare against.
/// An representing the inequality check.
public IPredicate isNotEqualTo(object value) => new NotEqualsPredicate(this, value);
/// Creates a predicate that checks whether the expression value is null.
/// An representing the null check.
public IPredicate isNull() => new IsNullPredicate(this);
/// Creates a predicate that checks whether the expression value is not null.
/// An representing the not-null check.
public IPredicate isNotNull() => new IsNotNullPredicate(this);
/// Creates a predicate that combines the current condition with another using logical AND.
/// The predicate to combine with.
/// An representing the AND combination.
public IPredicate and(IPredicate predicate) => new AndPredicate(this, predicate);
/// Creates a predicate that combines the current condition with another using logical OR.
/// The predicate to combine with.
/// An representing the OR combination.
public IPredicate or(IPredicate predicate) => new OrPredicate(this, predicate);
/// Creates a predicate that negates the current condition.
/// An representing the negated condition.
public IPredicate not() => new NotPredicate(this);
///
public virtual string ToTemplateString() =>
throw new NotSupportedException($"{GetType().Name} cannot be serialized to a template string.");
}