forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NamedValueDictionary.cs
222 lines (198 loc) · 7.41 KB
/
NamedValueDictionary.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Collections;
using System.Collections.Generic;
namespace Microsoft.Xna.Framework.Content.Pipeline
{
public class NamedValueDictionary<T> : IDictionary<string, T>
{
readonly Dictionary<string, T> dict = new Dictionary<string,T>();
/// <summary>
/// Initializes an instance of NamedValueDictionary.
/// </summary>
public NamedValueDictionary()
{
}
/// <summary>
/// Adds the specified key and value to the dictionary.
/// </summary>
/// <param name="key">Identity of the key of the new data pair.</param>
/// <param name="value">The value of the new data pair.</param>
public void Add(string key, T value)
{
dict.Add(key, value);
}
/// <summary>
/// Determines whether the specified key is present in the dictionary.
/// </summary>
/// <param name="key">Identity of a key.</param>
/// <returns></returns>
public bool ContainsKey(string key)
{
return dict.ContainsKey(key);
}
/// <summary>
/// Gets all keys contained in the dictionary.
/// </summary>
public ICollection<string> Keys
{
get { return dict.Keys; }
}
/// <summary>
/// Removes the specified key and value from the dictionary.
/// </summary>
/// <param name="key">Identity of the key to be removed.</param>
/// <returns>true if the value is present; false otherwise.</returns>
public bool Remove(string key)
{
return dict.Remove(key);
}
/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
/// <param name="key">Identity of the key of the element whose value is to be retrieved.</param>
/// <param name="value">The current value of the element.</param>
/// <returns>true if the value is present; false otherwise.</returns>
public bool TryGetValue(string key, out T value)
{
return dict.TryGetValue(key, out value);
}
/// <summary>
/// Specifies the type hint for the intermediate serializer. Values of this type do not store an explicit type attribute in the related XML source.
/// </summary>
protected internal virtual Type DefaultSerializerType
{
get { return typeof(T); }
}
/// <summary>
/// Gets all values contained in the dictionary.
/// </summary>
public ICollection<T> Values
{
get { return dict.Values; }
}
/// <summary>
/// Gets or sets the specified item.
/// </summary>
/// <param name="key">Identity of a key.</param>
public T this[string key]
{
get
{
return dict[key];
}
set
{
dict[key] = value;
}
}
/// <summary>
/// Adds an item to the collection.
/// </summary>
/// <param name="item">The item to add to the collection.</param>
void ICollection<KeyValuePair<string, T>>.Add(KeyValuePair<string, T> item)
{
((ICollection<KeyValuePair<string, T>>)dict).Add(item);
}
/// <summary>
/// Removes all keys and values from the dictionary.
/// </summary>
public void Clear()
{
dict.Clear();
}
/// <summary>
/// Determines whether the collection contains a specific value.
/// </summary>
/// <param name="item">The object to locate in the collection.</param>
/// <returns>true if the collection contains the object; false otherwise.</returns>
bool ICollection<KeyValuePair<string, T>>.Contains(KeyValuePair<string, T> item)
{
return ((ICollection<KeyValuePair<string, T>>)dict).Contains(item);
}
/// <summary>
/// Copies the elements of the collection to an array, starting at a specified index.
/// </summary>
/// <param name="array">The destination array.</param>
/// <param name="arrayIndex">The index at which to begin the copy.</param>
void ICollection<KeyValuePair<string, T>>.CopyTo(KeyValuePair<string, T>[] array, int arrayIndex)
{
((ICollection<KeyValuePair<string, T>>)dict).CopyTo(array, arrayIndex);
}
/// <summary>
/// Gets the number of items in the dictionary.
/// </summary>
public int Count
{
get { return dict.Count; }
}
/// <summary>
/// Gets a value indicating if this object is read-only.
/// </summary>
bool ICollection<KeyValuePair<string, T>>.IsReadOnly
{
get { return false; }
}
/// <summary>
/// Removes the first occurrence of the specified object from the collection.
/// </summary>
/// <param name="item">The item to remove from the collection.</param>
/// <returns>true if the item was successfully removed from the collection; false otherwise.</returns>
bool ICollection<KeyValuePair<string, T>>.Remove(KeyValuePair<string, T> item)
{
return ((ICollection<KeyValuePair<string, T>>)dict).Remove(item);
}
/// <summary>
/// Gets an enumerator that iterates through items in a dictionary.
/// </summary>
/// <returns>Enumerator for iterating through the dictionary.</returns>
public IEnumerator<KeyValuePair<string, T>> GetEnumerator()
{
return dict.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that can iterate through this collection.
/// </summary>
/// <returns>An enumerator that can iterate through this collection</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return dict.GetEnumerator();
}
/// <summary>
/// Adds an element to the dictionary.
/// </summary>
/// <param name="key">Identity of the key of the new element.</param>
/// <param name="value">The value of the new element.</param>
protected virtual void AddItem(string key, T value)
{
dict.Add(key, value);
}
/// <summary>
/// Removes all elements from the dictionary.
/// </summary>
protected virtual void ClearItems()
{
dict.Clear();
}
/// <summary>
/// Removes the specified element from the dictionary.
/// </summary>
/// <param name="key">Identity of the key of the data pair to be removed.</param>
/// <returns>true if the value is present; false otherwise.</returns>
protected virtual bool RemoveItem(string key)
{
return dict.Remove(key);
}
/// <summary>
/// Modifies the value of an existing element.
/// </summary>
/// <param name="key">Identity of the element to be modified.</param>
/// <param name="value">The value to be set.</param>
protected virtual void SetItem(string key, T value)
{
dict[key] = value;
}
}
}