-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDictionaryWrapper.cs
75 lines (63 loc) · 2.15 KB
/
DictionaryWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Open.Collections;
/// <inheritdoc />
[ExcludeFromCodeCoverage]
public class DictionaryWrapper<TKey, TValue>
: DictionaryWrapperBase<TKey, TValue, IDictionary<TKey, TValue>>
where TKey : notnull
{
/// <inheritdoc />
public DictionaryWrapper()
: base(new Dictionary<TKey, TValue>(), true) { }
/// <inheritdoc />
public DictionaryWrapper(int capacity)
: base(new Dictionary<TKey, TValue>(capacity), true) { }
/// <inheritdoc />
public DictionaryWrapper(IDictionary<TKey, TValue> source, bool owned = false)
: base(source, owned)
{
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override TValue GetValueInternal(TKey key)
=> InternalSource[key];
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void SetValueInternal(TKey key, TValue value)
=> InternalSource[key] = value;
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override ICollection<TKey> GetKeys()
=> new ReadOnlyCollectionAdapter<TKey>(
ThrowIfDisposed(InternalSource.Keys),
() => InternalSource.Count);
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override ICollection<TValue> GetValues()
=> new ReadOnlyCollectionAdapter<TValue>(
ThrowIfDisposed(InternalSource.Values),
() => InternalSource.Count);
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void AddInternal(TKey key, TValue value)
=> InternalSource.Add(key, value);
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool ContainsKey(TKey key)
=> InternalSource.ContainsKey(key);
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Remove(TKey key)
=> InternalSource.Remove(key);
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool TryGetValue(TKey key,
#if NET9_0_OR_GREATER
[MaybeNullWhen(false)]
#else
#endif
out TValue value)
=> InternalSource.TryGetValue(key, out value);
}