-
-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy pathReadOnlyConcurrentDictionary.cs
More file actions
43 lines (32 loc) · 1.8 KB
/
Copy pathReadOnlyConcurrentDictionary.cs
File metadata and controls
43 lines (32 loc) · 1.8 KB
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
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace DSharpPlus;
/// <summary>
/// Read-only view of a given <see cref="ConcurrentDictionary{TKey,TValue}"/>.
/// </summary>
/// <typeparam name="TKey">The type of keys in the dictionary.</typeparam>
/// <typeparam name="TValue">The type of values in the dictionary.</typeparam>
internal readonly struct ReadOnlyConcurrentDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
where TKey : notnull
{
private readonly ConcurrentDictionary<TKey, TValue> underlyingDict;
/// <summary>
/// Creates a new read-only view of the given dictionary.
/// </summary>
/// <param name="underlyingDict">Dictionary to create a view over.</param>
public ReadOnlyConcurrentDictionary(ConcurrentDictionary<TKey, TValue> underlyingDict) => this.underlyingDict = underlyingDict;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => this.underlyingDict.GetEnumerator();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.underlyingDict).GetEnumerator();
public int Count => this.underlyingDict.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ContainsKey(TKey key) => this.underlyingDict.ContainsKey(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetValue(TKey key, out TValue value) => this.underlyingDict.TryGetValue(key, out value);
public TValue this[TKey key] => this.underlyingDict[key];
public IEnumerable<TKey> Keys => this.underlyingDict.Keys;
public IEnumerable<TValue> Values => this.underlyingDict.Values;
}