Delegate BindArgumentsDelegate
Binds raw parser arguments to an opaque object that is cached with the route definition.
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public delegate object? BindArgumentsDelegate(IReadOnlyDictionary<string, string> rawArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyDictionary<string, string> | rawArgs | The raw parser arguments as parsed from the route template, keyed case-insensitively. |
Returns
| Type | Description |
|---|---|
| object | A parser-specific object that will later be exposed through Arguments. Return null when the parser does not need a bound payload. |
Remarks
This delegate runs during route registration, not during request processing. It is the right place to validate parser arguments, parse numeric limits, or precompile regular expressions once. Exceptions thrown by the delegate are reported while the route containing the parser arguments is registered.
Examples
routerBuilder.AddValueParser
(
"int",
static rawArgs =>
(
Min: rawArgs.TryGetValue("min", out string? min) ? int.Parse(min) : null,
Max: rawArgs.TryGetValue("max", out string? max) ? int.Parse(max) : null
),
static context =>
{
var args = ((int? Min, int? Max)) context.Arguments!;
return ValueTask.FromResult(new ValueParseResult(true, context.Segment));
}
);