< Summary

Class:Azure.Core.ChangeTrackingList`1
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\ChangeTrackingList.cs
Covered lines:31
Uncovered lines:30
Coverable lines:61
Total lines:192
Line coverage:50.8% (31 of 61)
Covered branches:11
Total branches:26
Branch coverage:42.3% (11 of 26)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
.ctor(...)-60%50%
.ctor(...)-60%50%
get_IsUndefined()-100%100%
Reset()-0%100%
GetEnumerator()-100%100%
<GetEnumerator()-100%100%
System.Collections.IEnumerable.GetEnumerator()-100%100%
Add(...)-100%100%
Clear()-100%100%
Contains(...)-100%100%
CopyTo(...)-0%0%
Remove(...)-0%0%
get_Count()-100%100%
get_IsReadOnly()-0%0%
IndexOf(...)-0%0%
Insert(...)-0%100%
RemoveAt(...)-0%0%
get_Item(...)-66.67%50%
set_Item(...)-0%0%
EnsureList()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\ChangeTrackingList.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections;
 6using System.Collections.Generic;
 7using System.Linq;
 8
 9#nullable enable
 10
 11namespace Azure.Core
 12{
 13    internal class ChangeTrackingList<T>: IList<T>, IReadOnlyList<T>
 14    {
 15        private IList<T>? _innerList;
 16
 4097717        public ChangeTrackingList()
 18        {
 4097719        }
 20
 39721        public ChangeTrackingList(Optional<IList<T>> optionalList) : this(optionalList.Value)
 22        {
 39723        }
 24
 1925        public ChangeTrackingList(Optional<IReadOnlyList<T>> optionalList) : this(optionalList.Value)
 26        {
 1927        }
 28
 1929        private ChangeTrackingList(IEnumerable<T> innerList)
 30        {
 1931            if (innerList == null)
 32            {
 1933                return;
 34            }
 35
 036            _innerList = innerList.ToList();
 037        }
 38
 39739        private ChangeTrackingList(IList<T> innerList)
 40        {
 39741            if (innerList == null)
 42            {
 39743                return;
 44            }
 45
 046            _innerList = innerList;
 047        }
 48
 2133849        public bool IsUndefined => _innerList == null;
 50
 51        public void Reset()
 52        {
 053            _innerList = null;
 054        }
 55
 56        public IEnumerator<T> GetEnumerator()
 57        {
 2015558            if (IsUndefined)
 59            {
 60                IEnumerator<T> EnumerateEmpty()
 61                {
 1666462                    yield break;
 63                }
 64
 1672865                return EnumerateEmpty();
 66            }
 342767            return EnsureList().GetEnumerator();
 68        }
 69
 70        IEnumerator IEnumerable.GetEnumerator()
 71        {
 51472            return GetEnumerator();
 73        }
 74
 75        public void Add(T item)
 76        {
 1141777            EnsureList().Add(item);
 1141778        }
 79
 80        public void Clear()
 81        {
 38682            EnsureList().Clear();
 38683        }
 84
 85        public bool Contains(T item)
 86        {
 29887            if (IsUndefined)
 88            {
 29689                return false;
 90            }
 91
 292            return EnsureList().Contains(item);
 93        }
 94
 95        public void CopyTo(T[] array, int arrayIndex)
 96        {
 097            if (IsUndefined)
 98            {
 099                return;
 100            }
 101
 0102            EnsureList().CopyTo(array, arrayIndex);
 0103        }
 104
 105        public bool Remove(T item)
 106        {
 0107            if (IsUndefined)
 108            {
 0109                return false;
 110            }
 111
 0112            return EnsureList().Remove(item);
 113        }
 114
 115        public int Count
 116        {
 117            get
 118            {
 226119                if (IsUndefined)
 120                {
 210121                    return 0;
 122                }
 16123                return EnsureList().Count;
 124            }
 125        }
 126
 127        public bool IsReadOnly
 128        {
 129            get
 130            {
 0131                if (IsUndefined)
 132                {
 0133                    return false;
 134                }
 135
 0136                return EnsureList().IsReadOnly;
 137            }
 138        }
 139
 140        public int IndexOf(T item)
 141        {
 0142            if (IsUndefined)
 143            {
 0144                return -1;
 145            }
 146
 0147            return EnsureList().IndexOf(item);
 148        }
 149
 150        public void Insert(int index, T item)
 151        {
 0152            EnsureList().Insert(index, item);
 0153        }
 154
 155        public void RemoveAt(int index)
 156        {
 0157            if (IsUndefined)
 158            {
 0159                throw new ArgumentOutOfRangeException(nameof(index));
 160            }
 161
 0162            EnsureList().RemoveAt(index);
 0163        }
 164
 165        public T this[int index]
 166        {
 167            get
 168            {
 4169                if (IsUndefined)
 170                {
 0171                    throw new ArgumentOutOfRangeException(nameof(index));
 172                }
 173
 4174                return EnsureList()[index];
 175            }
 176            set
 177            {
 0178                if (IsUndefined)
 179                {
 0180                    throw new ArgumentOutOfRangeException(nameof(index));
 181                }
 182
 0183                EnsureList()[index] = value;
 0184            }
 185        }
 186
 187        private IList<T> EnsureList()
 188        {
 15252189            return _innerList ??= new List<T>();
 190        }
 191    }
 192}