Path: redb-route/redb.Route/Definitions/TransformDefinition.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/TransformDefinition.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Leaf definition that transforms the exchange body using a factory function.
///
public sealed class TransformDefinition : ProcessorDefinition
{
private readonly Func _transform;
/// Creates a transform definition from a factory.
public TransformDefinition(Func transform)
{
ArgumentNullException.ThrowIfNull(transform);
_transform = transform;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new DelegateProcessor(exchange => exchange.In.Body = _transform(exchange));
}
///
/// Leaf definition that transforms the exchange body using an .
///
public sealed class TransformExpressionDefinition : ProcessorDefinition
{
private readonly IExpression _expression;
/// The expression producing the transformed body.
public IExpression Expression => _expression;
/// Creates a transform definition from an expression.
public TransformExpressionDefinition(IExpression expression)
{
ArgumentNullException.ThrowIfNull(expression);
_expression = expression;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new ExpressionBodyProcessor(_expression);
}