< Summary

Information
Class: NanoRoute.Internals.ParameterDefinition
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RoutePattern/ParameterDefinition.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 57
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
ParameterDefinition()51
Parse(...)391

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RoutePattern/ParameterDefinition.cs

#LineLine coverage
 1/********************************************************************************
 2* ParameterDefinition.cs                                                        *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Runtime.CompilerServices;
 8using System.Text.RegularExpressions;
 9
 10namespace NanoRoute.Internals
 11{
 12    using Properties;
 13
 14    internal readonly struct ParameterDefinition
 15    {
 16        private const string
 17            PARAMETER_NAME = $@"\w+\??",
 18            PARAMETER_NAME_PATTERN = $@"\G(?:(?<parameterName>{PARAMETER_NAME}):)?";
 19
 120        private static readonly Regex s_parameterName = new(PARAMETER_NAME_PATTERN, RuntimeFeature.IsDynamicCodeSupporte
 21
 22        public static ParameterDefinition Parse(string pattern, ref int offset)
 123        {
 124            int newOffset = offset;
 25
 126            if (newOffset < pattern.Length && pattern[newOffset++] == '{' && s_parameterName.Match(pattern, newOffset) i
 127            {
 128                string parameterName = parsed.Groups["parameterName"].Value;
 29
 130                newOffset += length;
 31
 132                ParameterDefinition result = new()
 133                {
 134                    ValueParser = ValueParserDefinition.Parse(pattern, ref newOffset),
 135                    ParameterName = parameterName.Length is 0 ? null : parameterName.TrimEnd('?'),
 136                    IsOptional = parameterName.EndsWith("?", StringComparison.Ordinal)
 137                };
 38
 139                if (newOffset < pattern.Length && pattern[newOffset] == '}')
 140                {
 141                    offset = newOffset;
 142                    return result;
 43                }
 144            }
 45
 146            throw new InvalidOperationException(string.Format(Resources.Culture, Resources.ERR_INVALID_PATTERN, offset))
 147        }
 48
 49        public required ValueParserDefinition ValueParser { get; init; }
 50
 51        public string? ParameterName { get; init; }
 52
 53        public bool IsOptional { get; init; }
 54
 55        public int Index { get; init; }
 56    }
 57}