-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathProjectResourceCollection.cs
More file actions
115 lines (94 loc) · 2.56 KB
/
Copy pathProjectResourceCollection.cs
File metadata and controls
115 lines (94 loc) · 2.56 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
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
108
109
110
111
112
113
114
115
using RPGCore.Packages;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace RPGCore.Projects;
[DebuggerDisplay("Count = {Count,nq}")]
[DebuggerTypeProxy(typeof(ProjectResourceCollectionDebugView))]
public sealed class ProjectResourceCollection : IResourceCollection
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Dictionary<string, ProjectResource> resources;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public int Count => resources.Count;
public ProjectResource this[string key] => resources[key];
IResource IResourceCollection.this[string key] => this[key];
internal ProjectResourceCollection()
{
resources = new Dictionary<string, ProjectResource>();
}
internal ProjectResourceCollection(Dictionary<string, ProjectResource> resources)
{
this.resources = resources ?? throw new System.ArgumentNullException(nameof(resources));
}
internal void Add(string key, ProjectResource resource)
{
resources.Add(key, resource);
}
public bool Contains(string key)
{
return resources.ContainsKey(key);
}
public bool TryGetResource(string key, out ProjectResource value)
{
return resources.TryGetValue(key, out value);
}
public IEnumerator<ProjectResource> GetEnumerator()
{
return resources.Values.GetEnumerator();
}
bool IResourceCollection.TryGetResource(string key, out IResource value)
{
bool result = TryGetResource(key, out var resource);
value = resource;
return result;
}
IEnumerator<IResource> IEnumerable<IResource>.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
private class ProjectResourceCollectionDebugView
{
[DebuggerDisplay("{Value}", Name = "{Key}")]
internal struct DebuggerRow
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public string Key;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public IResource Value;
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ProjectResourceCollection source;
public ProjectResourceCollectionDebugView(ProjectResourceCollection source)
{
this.source = source;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public DebuggerRow[] Keys
{
get
{
if (source.resources.Count == 0)
{
return null;
}
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;
}
}
}
}