< Summary

Information
Class: System.Text.Json.Serialization.Metadata.PropertyRefCacheBuilder
Assembly: System.Text.Json
File(s): C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\PropertyRefCacheBuilder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 36
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
ToArray()100%110%
TryAdd(...)0%220%

File(s)

C:\h\w\B31A098C\w\BB5A0A33\e\runtime-utils\Runner\runtime\src\libraries\System.Text.Json\src\System\Text\Json\Serialization\Metadata\PropertyRefCacheBuilder.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics;
 6
 7namespace System.Text.Json.Serialization.Metadata
 8{
 9    /// <summary>
 10    /// Defines builder type for constructing updated <see cref="PropertyRef"/> caches.
 11    /// </summary>
 012    internal sealed class PropertyRefCacheBuilder(PropertyRef[] originalCache)
 13    {
 14        public const int MaxCapacity = 64;
 015        private readonly List<PropertyRef> _propertyRefs = [];
 016        private readonly HashSet<PropertyRef> _added = [];
 17
 18        /// <summary>
 19        /// Stores a reference to the original cache off which the current list is being built.
 20        /// </summary>
 021        public readonly PropertyRef[] OriginalCache = originalCache;
 022        public int Count => _propertyRefs.Count;
 023        public int TotalCount => OriginalCache.Length + _propertyRefs.Count;
 024        public PropertyRef[] ToArray() => [.. OriginalCache, .. _propertyRefs];
 25
 26        public void TryAdd(PropertyRef propertyRef)
 027        {
 028            Debug.Assert(TotalCount < MaxCapacity, "Should have been checked by the caller.");
 29
 030            if (_added.Add(propertyRef))
 031            {
 032                _propertyRefs.Add(propertyRef);
 033            }
 034        }
 35    }
 36}