Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NameValueCollection.cs
Go to the documentation of this file.
2using System.Text;
3
5
7{
8 private string[] _all;
9
10 private string[] _allKeys;
11
12 public string? this[string? name]
13 {
14 get
15 {
16 return Get(name);
17 }
18 set
19 {
20 Set(name, value);
21 }
22 }
23
24 public string? this[int index] => Get(index);
25
26 public virtual string?[] AllKeys
27 {
28 get
29 {
30 if (_allKeys == null)
31 {
33 }
34 return _allKeys;
35 }
36 }
37
39 {
40 }
41
47
48 [Obsolete("This constructor has been deprecated. Use NameValueCollection(IEqualityComparer) instead.")]
53
55 : base(capacity)
56 {
57 }
58
63
68
71 {
72 if (col == null)
73 {
74 throw new ArgumentNullException("col");
75 }
76 base.Comparer = col.Comparer;
77 Add(col);
78 }
79
80 [Obsolete("This constructor has been deprecated. Use NameValueCollection(Int32, IEqualityComparer) instead.")]
85
87 : base(info, context)
88 {
89 }
90
91 protected void InvalidateCachedArrays()
92 {
93 _all = null;
94 _allKeys = null;
95 }
96
97 private static string GetAsOneString(ArrayList list)
98 {
99 int num = list?.Count ?? 0;
100 if (num == 1)
101 {
102 return (string)list[0];
103 }
104 if (num > 1)
105 {
107 for (int i = 1; i < num; i++)
108 {
109 stringBuilder.Append(',');
110 stringBuilder.Append((string)list[i]);
111 }
112 return stringBuilder.ToString();
113 }
114 return null;
115 }
116
117 private static string[] GetAsStringArray(ArrayList list)
118 {
119 int num = list?.Count ?? 0;
120 if (num == 0)
121 {
122 return null;
123 }
124 string[] array = new string[num];
125 list.CopyTo(0, array, 0, num);
126 return array;
127 }
128
130 {
131 if (c == null)
132 {
133 throw new ArgumentNullException("c");
134 }
136 int count = c.Count;
137 for (int i = 0; i < count; i++)
138 {
139 string key = c.GetKey(i);
140 string[] values = c.GetValues(i);
141 if (values != null)
142 {
143 for (int j = 0; j < values.Length; j++)
144 {
145 Add(key, values[j]);
146 }
147 }
148 else
149 {
150 Add(key, null);
151 }
152 }
153 }
154
155 public virtual void Clear()
156 {
157 if (base.IsReadOnly)
158 {
160 }
162 BaseClear();
163 }
164
165 public void CopyTo(Array dest, int index)
166 {
167 if (dest == null)
168 {
169 throw new ArgumentNullException("dest");
170 }
171 if (dest.Rank != 1)
172 {
173 throw new ArgumentException(System.SR.Arg_MultiRank, "dest");
174 }
175 if (index < 0)
176 {
178 }
179 if (dest.Length - index < Count)
180 {
182 }
183 int count = Count;
184 if (_all == null)
185 {
186 string[] array = new string[count];
187 for (int i = 0; i < count; i++)
188 {
189 array[i] = Get(i);
190 dest.SetValue(array[i], i + index);
191 }
192 _all = array;
193 }
194 else
195 {
196 for (int j = 0; j < count; j++)
197 {
198 dest.SetValue(_all[j], j + index);
199 }
200 }
201 }
202
203 public bool HasKeys()
204 {
205 return InternalHasKeys();
206 }
207
208 internal virtual bool InternalHasKeys()
209 {
210 return BaseHasKeys();
211 }
212
213 public virtual void Add(string? name, string? value)
214 {
215 if (base.IsReadOnly)
216 {
218 }
221 if (arrayList == null)
222 {
223 arrayList = new ArrayList(1);
224 if (value != null)
225 {
226 arrayList.Add(value);
227 }
228 BaseAdd(name, arrayList);
229 }
230 else if (value != null)
231 {
232 arrayList.Add(value);
233 }
234 }
235
236 public virtual string? Get(string? name)
237 {
239 return GetAsOneString(list);
240 }
241
242 public virtual string[]? GetValues(string? name)
243 {
245 return GetAsStringArray(list);
246 }
247
248 public virtual void Set(string? name, string? value)
249 {
250 if (base.IsReadOnly)
251 {
253 }
256 arrayList.Add(value);
257 BaseSet(name, arrayList);
258 }
259
260 public virtual void Remove(string? name)
261 {
263 BaseRemove(name);
264 }
265
266 public virtual string? Get(int index)
267 {
269 return GetAsOneString(list);
270 }
271
272 public virtual string[]? GetValues(int index)
273 {
275 return GetAsStringArray(list);
276 }
277
278 public virtual string? GetKey(int index)
279 {
280 return BaseGetKey(index);
281 }
282}
NameValueCollection(IEqualityComparer? equalityComparer)
NameValueCollection(IHashCodeProvider? hashProvider, IComparer? comparer)
NameValueCollection(SerializationInfo info, StreamingContext context)
virtual void Add(string? name, string? value)
NameValueCollection(int capacity, NameValueCollection col)
NameValueCollection(int capacity, IEqualityComparer? equalityComparer)
NameValueCollection(int capacity, IHashCodeProvider? hashProvider, IComparer? comparer)
virtual void Set(string? name, string? value)
static string CollectionReadOnly
Definition SR.cs:28
static string Arg_MultiRank
Definition SR.cs:24
static string ArgumentOutOfRange_NeedNonNegNum_Index
Definition SR.cs:18
static string Arg_InsufficientSpace
Definition SR.cs:26
Definition SR.cs:7