-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTags.cs
59 lines (47 loc) · 1.72 KB
/
Tags.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
namespace Teraa.Irc;
/// <summary>
/// Type representing a collection of key/value pairs of <see cref="IMessage"/> tags.
/// </summary>
[PublicAPI]
public interface ITags : IReadOnlyDictionary<string, string> { }
/// <inheritdoc />
[PublicAPI]
public class Tags : ITags
{
private readonly IReadOnlyDictionary<string, string> _tags;
/// <summary>
/// Initializes a new <see cref="Tags"/> instance with the provided <see cref="IReadOnlyDictionary{TKey, TValue}"/>.
/// </summary>
/// <param name="tags">A <see cref="IReadOnlyDictionary{TKey, TValue}"/> containing tag key/value pairs.</param>
/// <exception cref="ArgumentNullException"><paramref name="tags"/> is null.</exception>
public Tags(IReadOnlyDictionary<string, string> tags)
=> _tags = tags ?? throw new ArgumentNullException(nameof(tags));
/// <inheritdoc/>
public string this[string key]
=> _tags[key];
/// <inheritdoc/>
public IEnumerable<string> Keys
=> _tags.Keys;
/// <inheritdoc/>
public IEnumerable<string> Values
=> _tags.Values;
/// <inheritdoc/>
public int Count
=> _tags.Count;
/// <inheritdoc/>
public bool ContainsKey(string key)
=> _tags.ContainsKey(key);
/// <inheritdoc/>
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
=> _tags.GetEnumerator();
/// <inheritdoc/>
public bool TryGetValue(string key, [MaybeNullWhen(false)] out string value)
=> _tags.TryGetValue(key, out value);
IEnumerator IEnumerable.GetEnumerator()
=> _tags.GetEnumerator();
}