Path: redb-route/redb.Route/Expressions/TypedXPathExpression.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/TypedXPathExpression.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Expressions;
///
/// An XPath expression that remembers the target CLR type .
/// When the pipeline calls Evaluate<object>(exchange), the stored type is used
/// for the internal call, ensuring proper
/// type conversion (e.g., xpath<bool>("//active") returns a boxed
/// instead of a raw string).
///
/// The target CLR type for XPath result conversion.
public sealed class TypedXPathExpression : Expression
{
private readonly XPathExpression _inner;
///
/// Initializes a new instance of the class.
///
/// The XPath expression string.
///
/// The XPath-level type of the result, applied before conversion to .
///
/// What to run the path against; null means the message body.
public TypedXPathExpression(string xpath, XPathResult result = XPathResult.NodeSet, IExpression? source = null)
: this(new XPathExpression(xpath, null, result, source))
{
}
private TypedXPathExpression(XPathExpression inner) => _inner = inner;
///
public TypedXPathExpression From(IExpression source) => new(_inner.From(source));
///
public TypedXPathExpression WithNamespaces(params (string Prefix, string Uri)[] namespaces)
=> new(_inner.WithNamespaces(namespaces));
///
public TypedXPathExpression Trimmed(bool trim = true) => new(_inner.Trimmed(trim));
///
public TypedXPathExpression WithParameters(params (string Name, IExpression Value)[] parameters)
=> new(_inner.WithParameters(parameters));
///
public override T Evaluate(IExchange exchange)
{
// When the processor asks for Evaluate