Path: redb-route/redb.Route/Definitions/FilterDefinition.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/Definitions/FilterDefinition.cs
----
using redb.Route.Abstractions;
using redb.Route.Expressions;
using redb.Route.Predicates;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Scope-opener definition for the Filter EIP.
/// When is called, compiles all child
/// into an inner pipeline wrapped by a .
/// Close the scope with .
///
/// Inherits the entire fluent leaf-DSL from
/// with = ; calls like
/// To(...), Process(...), SetBody(...) therefore return
/// directly without locally-redeclared overloads.
///
///
public class FilterDefinition : RouteDefinitionBase, IRouteScope, ICompositeScope, IConditionSource
{
private readonly IPredicate _predicate;
///
public IPredicate? SourcePredicate { get; internal set; }
///
public IExpression? SourceExpression { get; internal set; }
///
public string? SourceTemplate { get; internal set; }
internal FilterDefinition(IPredicate predicate)
{
ArgumentNullException.ThrowIfNull(predicate);
_predicate = predicate;
}
internal FilterDefinition(Func predicate)
: this(new LambdaPredicate(predicate ?? throw new ArgumentNullException(nameof(predicate))))
{
}
///
public override IProcessor CreateProcessor(IRouteContext context)
{
IProcessor body = NodePipeline.Body(context, Outputs);
return new FilterProcessor(_predicate, body);
}
/// Closes this filter scope and returns the parent route definition.
/// Thrown if no parent route is set.
public IRouteDefinition EndFilter()
=> (IRouteDefinition)(Parent ?? throw new InvalidOperationException(
"EndFilter() called without a parent route. Ensure Filter() was called on a route definition."));
///
public IRouteDefinition End() => EndFilter();
}