< Summary

Information
Class: NanoRoute.Internals.RouteNode
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RouteNode.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 71
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
RouteNode()60
RouteNode(...)330
Copy(...)20

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RouteNode.cs

#LineLine coverage
 1/********************************************************************************
 2* RouteNode.cs                                                                  *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Collections.Frozen;
 8using System.Collections.Generic;
 9using System.Collections.Immutable;
 10
 11namespace NanoRoute.Internals
 12{
 13    /// <summary>
 14    /// Represents a node in the per-verb route tree.
 15    /// </summary>
 216    internal sealed class RouteNode()
 17    {
 18        /// <summary>
 19        /// Gets the handlers registered for the current route node.
 20        /// </summary>
 221        public IDictionary<HttpVerb, IList<HandlerRegistration>> HandlerRegistrations { get; } = new Dictionary<HttpVerb
 22
 23        /// <summary>
 24        /// Gets the parser used by this node when it represents a parameterized segment.
 25        /// </summary>
 26        public ParameterParser? ParameterParser { get; init; }
 27
 28        /// <summary>
 29        /// Gets literal child nodes keyed by case-insensitive segment value.
 30        /// </summary>
 231        public IDictionary<ReadOnlyMemory<char>, RouteNode> LiteralChildren { get; } = new Dictionary<ReadOnlyMemory<cha
 32
 33        /// <summary>
 34        /// Gets parser-based child nodes evaluated after literal matches.
 35        /// </summary>
 236        public IList<RouteNode> ParsedChildren { get; } = new List<RouteNode>();
 37
 38        /// <summary>
 39        /// Returns true if this node is read-only.
 40        /// </summary>
 41        public bool Frozen { get; }
 42
 243        private RouteNode(RouteNode src, bool freeze): this()
 244        {
 245            ParameterParser = src.ParameterParser;
 46
 247            CopyCollection(src.ParsedChildren, ParsedChildren, c => c.Copy(freeze));
 248            CopyCollection(src.HandlerRegistrations, HandlerRegistrations, static kvp => new(kvp.Key, [.. kvp.Value]));
 249            CopyCollection(src.LiteralChildren, LiteralChildren, kvp => new(kvp.Key, kvp.Value.Copy(freeze)));
 50
 251            if (freeze)
 252            {
 253                LiteralChildren = LiteralChildren.ToFrozenDictionary(ReadOnlyMemoryCharComparer.Instance);
 254                ParsedChildren = ParsedChildren.ToImmutableArray();
 255                HandlerRegistrations = HandlerRegistrations.ToFrozenDictionary(static kvp => kvp.Key, static kvp => (ILi
 256                Frozen = true;
 257            }
 58
 59            static void CopyCollection<TValue>(ICollection<TValue> src, ICollection<TValue> dst, Func<TValue, TValue> va
 60            {
 61                foreach (TValue item in src)
 62                    dst.Add(valueCopy(item));
 63            }
 264        }
 65
 66        /// <summary>
 67        /// Creates a deep-copy from this node.
 68        /// </summary>
 269        public RouteNode Copy(bool frozen) => new(this, frozen);
 70    }
 71}