< Summary

Information
Class: NanoRoute.Internals.ParameterDefinition
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/Dsl/ParameterDefinition.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 64
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/Dsl/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
 137                    (
 138#if NETSTANDARD2_1_OR_GREATER
 139                        '?'
 140#else
 141                        "?"
 142#endif
 143                    )
 144                };
 45
 146                if (newOffset < pattern.Length && pattern[newOffset] == '}')
 147                {
 148                    offset = newOffset;
 149                    return result;
 50                }
 151            }
 52
 153            throw new ArgumentException(string.Format(Resources.Culture, Resources.ERR_INVALID_PATTERN, offset), nameof(
 154        }
 55
 56        public required ValueParserDefinition ValueParser { get; init; }
 57
 58        public string? ParameterName { get; init; }
 59
 60        public bool IsOptional { get; init; }
 61
 62        public int Index { get; init; }
 63    }
 64}