< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 65
Coverable lines: 65
Total lines: 125
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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(...)0%220%
OnCollectionModified()100%110%
ValidateAddedValue(...)100%110%
Add(...)100%110%
Clear()100%110%
Contains(...)100%110%
CopyTo(...)100%110%
GetEnumerator()100%110%
IndexOf(...)100%110%
Insert(...)100%110%
Remove(...)0%220%
RemoveAt(...)100%110%
System.Collections.Generic.IEnumerable<TItem>.GetEnumerator()100%110%
System.Collections.IEnumerable.GetEnumerator()100%110%
.ctor(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConfigurationList.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;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7
 8namespace System.Text.Json.Serialization
 9{
 10    /// <summary>
 11    /// A list of configuration items that can be locked for modification
 12    /// </summary>
 13    [DebuggerDisplay("{DebuggerDisplay,nq}")]
 14    [DebuggerTypeProxy(typeof(ConfigurationList<>.ConfigurationListDebugView))]
 15    internal abstract class ConfigurationList<TItem> : IList<TItem>
 16    {
 17        protected readonly List<TItem> _list;
 18
 019        public ConfigurationList(IEnumerable<TItem>? source = null)
 020        {
 021            _list = source is null ? new List<TItem>() : new List<TItem>(source);
 022        }
 23
 24        public abstract bool IsReadOnly { get; }
 25        protected abstract void OnCollectionModifying();
 026        protected virtual void OnCollectionModified() { }
 027        protected virtual void ValidateAddedValue(TItem item) { }
 28
 29        public TItem this[int index]
 30        {
 31            get
 032            {
 033                return _list[index];
 034            }
 35            set
 036            {
 037                ArgumentNullException.ThrowIfNull(value);
 38
 039                OnCollectionModifying();
 040                ValidateAddedValue(value);
 041                _list[index] = value;
 042                OnCollectionModified();
 043            }
 44        }
 45
 046        public int Count => _list.Count;
 47
 48        public void Add(TItem item)
 049        {
 050            ArgumentNullException.ThrowIfNull(item);
 51
 052            OnCollectionModifying();
 053            ValidateAddedValue(item);
 054            _list.Add(item);
 055            OnCollectionModified();
 056        }
 57
 58        public void Clear()
 059        {
 060            OnCollectionModifying();
 061            _list.Clear();
 062            OnCollectionModified();
 063        }
 64
 065        public bool Contains(TItem item) => _list.Contains(item);
 66
 67        public void CopyTo(TItem[] array, int arrayIndex)
 068        {
 069            _list.CopyTo(array, arrayIndex);
 070        }
 71
 072        public List<TItem>.Enumerator GetEnumerator() => _list.GetEnumerator();
 73
 074        public int IndexOf(TItem item) => _list.IndexOf(item);
 75
 76        public void Insert(int index, TItem item)
 077        {
 078            ArgumentNullException.ThrowIfNull(item);
 79
 080            OnCollectionModifying();
 081            ValidateAddedValue(item);
 082            _list.Insert(index, item);
 083            OnCollectionModified();
 084        }
 85
 86        public bool Remove(TItem item)
 087        {
 088            OnCollectionModifying();
 089            bool removed = _list.Remove(item);
 090            if (removed)
 091            {
 092                OnCollectionModified();
 093            }
 94
 095            return removed;
 096        }
 97
 98        public void RemoveAt(int index)
 099        {
 0100            OnCollectionModifying();
 0101            _list.RemoveAt(index);
 0102            OnCollectionModified();
 0103        }
 104
 105        IEnumerator<TItem> IEnumerable<TItem>.GetEnumerator()
 0106        {
 0107            return _list.GetEnumerator();
 0108        }
 109
 110        IEnumerator IEnumerable.GetEnumerator()
 0111        {
 0112            return _list.GetEnumerator();
 0113        }
 114
 115        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 0116        private string DebuggerDisplay => $"Count = {Count}, IsReadOnly = {IsReadOnly}";
 117
 0118        private sealed class ConfigurationListDebugView(ConfigurationList<TItem> collection)
 119        {
 120            [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
 0121            public TItem[] Items => collection._list.ToArray();
 122        }
 123    }
 124}
 125