Path: redb-route/redb.Route/Expressions/CompiledJPathExpression.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/CompiledJPathExpression.cs
----
using System;
using redb.Route.Abstractions;
namespace redb.Route.Expressions;
///
/// A compiled JPath expression that evaluates a dynamic JSON path using a delegate
/// and then delegates the actual JSON path evaluation to .
///
public class CompiledJPathExpression
{
private readonly Func _pathDelegate;
///
/// Initializes a new instance of the class.
///
/// A delegate that computes the JSON path string from an .
public CompiledJPathExpression(Func pathDelegate)
{
_pathDelegate = pathDelegate;
}
///
/// Evaluates the dynamic JSON path expression against the exchange.
///
/// The type of the return value.
/// The exchange containing the message data.
/// The value extracted by the computed JSON path, converted to .
public T Evaluate(IExchange exchange)
{
// Compute the path using the delegate
var path = _pathDelegate(exchange)?.ToString();
if (string.IsNullOrEmpty(path))
{
return default(T);
}
// Create a JsonPathExpression with the computed path
var jsonPathExpression = new JsonPathExpression(path);
// Evaluate the value at the path
return jsonPathExpression.Evaluate(exchange);
}
}