< Summary

Class:Azure.Core.ChangeTrackingList`1
Assembly:Azure.Security.KeyVault.Administration
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\ChangeTrackingList.cs
Covered lines:0
Uncovered lines:61
Coverable lines:61
Total lines:192
Line coverage:0% (0 of 61)
Covered branches:0
Total branches:26
Branch coverage:0% (0 of 26)

Metrics

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

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
 017        public ChangeTrackingList()
 18        {
 019        }
 20
 021        public ChangeTrackingList(Optional<IList<T>> optionalList) : this(optionalList.Value)
 22        {
 023        }
 24
 025        public ChangeTrackingList(Optional<IReadOnlyList<T>> optionalList) : this(optionalList.Value)
 26        {
 027        }
 28
 029        private ChangeTrackingList(IEnumerable<T> innerList)
 30        {
 031            if (innerList == null)
 32            {
 033                return;
 34            }
 35
 036            _innerList = innerList.ToList();
 037        }
 38
 039        private ChangeTrackingList(IList<T> innerList)
 40        {
 041            if (innerList == null)
 42            {
 043                return;
 44            }
 45
 046            _innerList = innerList;
 047        }
 48
 049        public bool IsUndefined => _innerList == null;
 50
 51        public void Reset()
 52        {
 053            _innerList = null;
 054        }
 55
 56        public IEnumerator<T> GetEnumerator()
 57        {
 058            if (IsUndefined)
 59            {
 60                IEnumerator<T> EnumerateEmpty()
 61                {
 062                    yield break;
 63                }
 64
 065                return EnumerateEmpty();
 66            }
 067            return EnsureList().GetEnumerator();
 68        }
 69
 70        IEnumerator IEnumerable.GetEnumerator()
 71        {
 072            return GetEnumerator();
 73        }
 74
 75        public void Add(T item)
 76        {
 077            EnsureList().Add(item);
 078        }
 79
 80        public void Clear()
 81        {
 082            EnsureList().Clear();
 083        }
 84
 85        public bool Contains(T item)
 86        {
 087            if (IsUndefined)
 88            {
 089                return false;
 90            }
 91
 092            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            {
 0119                if (IsUndefined)
 120                {
 0121                    return 0;
 122                }
 0123                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            {
 0169                if (IsUndefined)
 170                {
 0171                    throw new ArgumentOutOfRangeException(nameof(index));
 172                }
 173
 0174                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        {
 0189            return _innerList ??= new List<T>();
 190        }
 191    }
 192}