-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReadOnlyKeyedTopicCollection{T}.cs
77 lines (68 loc) · 4.13 KB
/
ReadOnlyKeyedTopicCollection{T}.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
76
77
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using System.Collections.ObjectModel;
namespace OnTopic.Collections {
/*============================================================================================================================
| CLASS: READ-ONLY KEYED TOPIC COLLECTION
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a read-only collection of topics.
/// </summary>
public class ReadOnlyKeyedTopicCollection<T> : ReadOnlyCollection<T> where T : Topic {
/*==========================================================================================================================
| PRIVATE VARIABLES
\-------------------------------------------------------------------------------------------------------------------------*/
private readonly KeyedTopicCollection<T> _innerCollection;
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a new <see cref="ReadOnlyKeyedTopicCollection{T}"/> based on an existing <see cref="IList{T}"/>.
/// </summary>
/// <param name="innerCollection">The underlying <see cref="KeyedTopicCollection{T}"/>.</param>
public ReadOnlyKeyedTopicCollection(IList<T>? innerCollection = null) : base(innerCollection?? new List<T>()) {
_innerCollection = innerCollection as KeyedTopicCollection<T>?? new(innerCollection);
}
/*==========================================================================================================================
| FACTORY METHOD: FROM LIST
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes a new <see cref="ReadOnlyTopicCollection{T}"/> based on an existing <see cref="List{T}"/>.
/// </summary>
/// <remarks>
/// The <paramref name="innerCollection"/> will be converted to a <see cref="TopicCollection{T}"/>.
/// </remarks>
/// <param name="innerCollection">The underlying <see cref="TopicCollection{T}"/>.</param>
[ExcludeFromCodeCoverage]
[Obsolete("This is effectively satisfied by the related overload, and has been removed.", true)]
public ReadOnlyTopicCollection<T> FromList(IList<T> innerCollection) => throw new NotImplementedException();
/*==========================================================================================================================
| METHOD: GET VALUE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves a <typeparamref name="T"/> by <paramref name="key"/>.
/// </summary>
public T? GetValue(string key) {
TopicFactory.ValidateKey(key);
if (_innerCollection.Contains(key)) {
return _innerCollection[key];
}
return null;
}
/// <inheritdoc cref="GetValue(String)"/>
[ExcludeFromCodeCoverage]
[Obsolete($"The {nameof(GetTopic)} method has been renamed to {nameof(GetValue)}.", true)]
public T? GetTopic(string key) => GetValue(key);
/*==========================================================================================================================
| INDEXER
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves an <see cref="Topic"/> by key.
/// </summary>
/// <param name="key">The topic key.</param>
public Topic this[string key] => _innerCollection[key];
} //Class
} //Namespace