Delegate SyncValueParserDelegate

Represents a synchronous value parser.

Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public delegate bool SyncValueParserDelegate(ReadOnlyMemory<char> segment, object? arguments, out object? parsed)
Parameters
Type Name Description
ReadOnlyMemory<char> segment

The decoded segment extracted from the request URI.

object arguments

The parser-specific argument payload produced by BindArgumentsDelegate during route registration, or null when the parser was registered without arguments.

object parsed

The parsed value when the delegate returns true; otherwise null.

Returns
Type Description
bool

true when the segment is accepted by the parser; otherwise false.

Examples
routerBuilder.AddValueParser("int", (string segment, object? arguments, out object? parsed) =>
{
    var limits = ((int? Min, int? Max)) arguments!;

    if (int.TryParse(segment, out int value))
    {
        if (limits.Min.HasValue && value < limits.Min.Value)
        {
            parsed = null;
            return false;
        }

        parsed = value;
        return true;
    }

    parsed = null;
    return false;
});
In this article
Back to top Generated by DocFX