Path: redb-route/redb.Route/Expressions/PropertyExpression.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/PropertyExpression.cs
----
using System;
using redb.Route.Abstractions;
namespace redb.Route.Expressions;
///
/// Expression for accessing properties in an .
///
///
/// Allows extracting exchange property values
/// for use in predicates and routing logic.
///
public class PropertyExpression : Expression
{
private readonly string _propertyName;
///
/// Initializes a new instance of the class.
///
/// The property name (case-sensitive).
/// Thrown when is null.
public PropertyExpression(string propertyName)
{
_propertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
}
///
/// Thrown when is null.
/// Thrown when the property type is not compatible with .
/// Thrown when the property is not found.
public override T Evaluate(IExchange exchange)
{
if (exchange == null)
throw new ArgumentNullException(nameof(exchange));
return exchange.getProperty(_propertyName);
}
///
/// Thrown when is null.
public override void SetValue(IExchange exchange, object value)
{
if (exchange == null)
throw new ArgumentNullException(nameof(exchange));
exchange.setProperty(_propertyName, value);
}
///
public override string ToTemplateString() => $"${{property.{_propertyName}}}";
}