< Summary

Class:Azure.Core.ChangeTrackingDictionary`2
Assembly:Azure.Data.Tables
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\ChangeTrackingDictionary.cs
Covered lines:0
Uncovered lines:67
Coverable lines:67
Total lines:215
Line coverage:0% (0 of 67)
Covered branches:0
Total branches:32
Branch coverage:0% (0 of 32)

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%
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%
Add(...)-0%100%
ContainsKey(...)-0%0%
Remove(...)-0%0%
TryGetValue(...)-0%0%
get_Item(...)-0%0%
set_Item(...)-0%100%
System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>.get_Keys()-0%100%
System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>.get_Values()-0%100%
get_Keys()-0%0%
get_Values()-0%0%
EnsureDictionary()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\AutoRest\ChangeTrackingDictionary.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;
 7
 8#nullable enable
 9
 10namespace Azure.Core
 11{
 12    internal class ChangeTrackingDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>
 13    {
 14        private IDictionary<TKey, TValue>? _innerDictionary;
 15
 016        public ChangeTrackingDictionary()
 17        {
 018        }
 19
 020        public ChangeTrackingDictionary(Optional<IReadOnlyDictionary<TKey, TValue>> optionalDictionary) : this(optionalD
 21        {
 022        }
 23
 024        public ChangeTrackingDictionary(Optional<IDictionary<TKey, TValue>> optionalDictionary) : this(optionalDictionar
 25        {
 026        }
 27
 028        private ChangeTrackingDictionary(IDictionary<TKey, TValue> dictionary)
 29        {
 030            if (dictionary == null) return;
 31
 032            _innerDictionary = new Dictionary<TKey, TValue>(dictionary);
 033        }
 34
 035        private ChangeTrackingDictionary(IReadOnlyDictionary<TKey, TValue> dictionary)
 36        {
 037            if (dictionary == null) return;
 38
 039            _innerDictionary = new Dictionary<TKey, TValue>();
 040            foreach (KeyValuePair<TKey, TValue> pair in dictionary)
 41            {
 042                _innerDictionary.Add(pair);
 43            }
 044        }
 45
 046        public bool IsUndefined => _innerDictionary == null;
 47
 48        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
 49        {
 050            if (IsUndefined)
 51            {
 52                IEnumerator<KeyValuePair<TKey, TValue>> GetEmptyEnumerator()
 53                {
 054                    yield break;
 55                }
 056                return GetEmptyEnumerator();
 57            }
 058            return EnsureDictionary().GetEnumerator();
 59        }
 60
 61        IEnumerator IEnumerable.GetEnumerator()
 62        {
 063            return GetEnumerator();
 64        }
 65
 66        public void Add(KeyValuePair<TKey, TValue> item)
 67        {
 068            EnsureDictionary().Add(item);
 069        }
 70
 71        public void Clear()
 72        {
 073            EnsureDictionary().Clear();
 074        }
 75
 76        public bool Contains(KeyValuePair<TKey, TValue> item)
 77        {
 078            if (IsUndefined)
 79            {
 080                return false;
 81            }
 82
 083            return EnsureDictionary().Contains(item);
 84        }
 85
 86        public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
 87        {
 088            if (IsUndefined)
 89            {
 090                return;
 91            }
 92
 093            EnsureDictionary().CopyTo(array, arrayIndex);
 094        }
 95
 96        public bool Remove(KeyValuePair<TKey, TValue> item)
 97        {
 098            if (IsUndefined)
 99            {
 0100                return false;
 101            }
 102
 0103            return EnsureDictionary().Remove(item);
 104        }
 105
 106        public int Count
 107        {
 108            get
 109            {
 0110                if (IsUndefined)
 111                {
 0112                    return 0;
 113                }
 114
 0115                return EnsureDictionary().Count;
 116            }
 117        }
 118
 119        public bool IsReadOnly
 120        {
 121            get
 122            {
 0123                if (IsUndefined)
 124                {
 0125                    return false;
 126                }
 0127                return EnsureDictionary().IsReadOnly;
 128            }
 129        }
 130
 131        public void Add(TKey key, TValue value)
 132        {
 0133            EnsureDictionary().Add(key, value);
 0134        }
 135
 136        public bool ContainsKey(TKey key)
 137        {
 0138            if (IsUndefined)
 139            {
 0140                return false;
 141            }
 142
 0143            return EnsureDictionary().ContainsKey(key);
 144        }
 145
 146        public bool Remove(TKey key)
 147        {
 0148            if (IsUndefined)
 149            {
 0150                return false;
 151            }
 152
 0153            return EnsureDictionary().Remove(key);
 154        }
 155
 156        public bool TryGetValue(TKey key, out TValue value)
 157        {
 0158            if (IsUndefined)
 159            {
 0160                value = default!;
 0161                return false;
 162            }
 0163            return EnsureDictionary().TryGetValue(key, out value);
 164        }
 165
 166        public TValue this[TKey key]
 167        {
 168            get
 169            {
 0170                if (IsUndefined)
 171                {
 0172                    throw new KeyNotFoundException(nameof(key));
 173                }
 174
 0175                return EnsureDictionary()[key];
 176            }
 0177            set => EnsureDictionary()[key] = value;
 178        }
 179
 0180        IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys;
 181
 0182        IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
 183
 184        public ICollection<TKey> Keys
 185        {
 186            get
 187            {
 0188                if (IsUndefined)
 189                {
 0190                    return Array.Empty<TKey>();
 191                }
 192
 0193                return EnsureDictionary().Keys;
 194            }
 195        }
 196
 197        public ICollection<TValue> Values
 198        {
 199            get
 200            {
 0201                if (IsUndefined)
 202                {
 0203                    return Array.Empty<TValue>();
 204                }
 205
 0206                return EnsureDictionary().Values;
 207            }
 208        }
 209
 210        private IDictionary<TKey, TValue> EnsureDictionary()
 211        {
 0212            return _innerDictionary ??= new Dictionary<TKey, TValue>();
 213        }
 214    }
 215}