Path: redb-route/redb.Route/Expressions/ExpressionResolver.TemplateText.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/ExpressionResolver.TemplateText.cs
----
using System.Globalization;
namespace redb.Route.Expressions;
/// Partial class ExpressionResolver — how a ${...} hole becomes text.
public static partial class ExpressionResolver
{
///
/// Renders one substituted value of a ${...} template. Numbers and dates are written
/// culture-invariant (dates as ISO 8601), so a route renders the same text on every machine;
/// locale-specific formatting is an explicit choice (format(x, 'N2', 'ru-RU')), not the
/// server's accident. Strings and booleans are unchanged.
///
internal static string TemplateText(object? value) => value switch
{
null => string.Empty,
string s => s,
bool b => b.ToString(),
DateTime d => d.ToString("o", CultureInfo.InvariantCulture),
DateTimeOffset d => d.ToString("o", CultureInfo.InvariantCulture),
IFormattable f => f.ToString(null, CultureInfo.InvariantCulture),
_ => value.ToString() ?? string.Empty,
};
}