-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientResourceCollection{T}.cs
More file actions
57 lines (51 loc) · 2.8 KB
/
ClientResourceCollection{T}.cs
File metadata and controls
57 lines (51 loc) · 2.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
namespace OnTopic.Editor.AspNetCore.Models.ClientResources {
/*============================================================================================================================
| CLASS: CLIENT RESOURCE COLLECTION
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Represents a collection of <typeparamref name="T"/> instances, which are derived from <see cref="ClientResource"/>.
/// </summary>
public abstract class ClientResourceCollection<T>: KeyedCollection<Uri, T> where T: ClientResource, new() {
/*==========================================================================================================================
| METHOD: REGISTER
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Registers a client-side resource.
/// </summary>
/// <param name="uri">The relative or absolute URL so the client-side resource.</param>
public void Register(Uri uri) {
if (!Contains(uri)) {
Add(
new() {
Url = uri
}
);
}
}
/*==========================================================================================================================
| METHOD: GET RESOURCES
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves a collection of resources.
/// </summary>
public virtual ReadOnlyCollection<T> GetResources() => new(Items);
/*==========================================================================================================================
| OVERRIDE: GET KEY FOR ITEM
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Method must be overridden for the <see cref="ClientResourceCollection{T}"/> to extract the keys from the <typeparamref
/// name="T"/> instances.
/// </summary>
/// <param name="item">The <typeparamref name="T"/> object from which to extract the key.</param>
/// <returns>The key for the specified collection item.</returns>
protected override Uri GetKeyForItem(T item) {
Contract.Assume(item, "Assumes the item is available when deriving its key.");
return item.Url;
}
}
}