forked from Fydar/RPGCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageResourceCollection.cs
107 lines (89 loc) · 2.41 KB
/
PackageResourceCollection.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace RPGCore.Packages
{
/// <summary>
/// Represents a collection of <see cref="PackageResource"/>.
/// </summary>
[DebuggerDisplay("Count = {Count,nq}")]
[DebuggerTypeProxy(typeof(PackageResourceCollectionDebugView))]
public sealed class PackageResourceCollection : IResourceCollection
{
private readonly Dictionary<string, PackageResource> resources;
/// <inheritdoc/>
public int Count => resources.Count;
public PackageResource this[string key] => resources[key];
IResource IResourceCollection.this[string key] => this[key];
internal PackageResourceCollection()
{
resources = new Dictionary<string, PackageResource>();
}
public bool Contains(string key)
{
return resources.ContainsKey(key);
}
public bool TryGetResource(string key, out PackageResource value)
{
return resources.TryGetValue(key, out value);
}
internal void Add(string key, PackageResource asset)
{
resources.Add(key, asset);
}
bool IResourceCollection.TryGetResource(string key, out IResource value)
{
bool result = TryGetResource(key, out var resource);
value = resource;
return result;
}
public IEnumerator<PackageResource> GetEnumerator()
{
return resources.Values.GetEnumerator();
}
IEnumerator<IResource> IEnumerable<IResource>.GetEnumerator()
{
return resources.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return resources.Values.GetEnumerator();
}
private class PackageResourceCollectionDebugView
{
[DebuggerDisplay("{Value}", Name = "{Key}")]
internal struct DebuggerRow
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public string Key;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public IResource Value;
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly PackageResourceCollection source;
public PackageResourceCollectionDebugView(PackageResourceCollection source)
{
this.source = source;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public DebuggerRow[] Keys
{
get
{
var keys = new DebuggerRow[source.resources.Count];
int i = 0;
foreach (var kvp in source.resources)
{
keys[i] = new DebuggerRow
{
Key = kvp.Key,
Value = kvp.Value
};
i++;
}
return keys;
}
}
}
}
}