Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EventDescriptorCollection.cs
Go to the documentation of this file.
3
5
7{
8 private sealed class ArraySubsetEnumerator : IEnumerator
9 {
10 private readonly Array _array;
11
12 private readonly int _total;
13
14 private int _current;
15
16 public object Current
17 {
18 get
19 {
20 if (_current == -1)
21 {
22 throw new InvalidOperationException();
23 }
24 return _array.GetValue(_current);
25 }
26 }
27
29 {
30 _array = array;
31 _total = count;
32 _current = -1;
33 }
34
35 public bool MoveNext()
36 {
37 if (_current < _total - 1)
38 {
39 _current++;
40 return true;
41 }
42 return false;
43 }
44
45 public void Reset()
46 {
47 _current = -1;
48 }
49 }
50
52
53 private readonly string[] _namedSort;
54
55 private readonly IComparer _comparer;
56
57 private bool _eventsOwned;
58
59 private bool _needSort;
60
61 private readonly bool _readOnly;
62
64
65 public int Count { get; private set; }
66
67 public virtual EventDescriptor? this[int index]
68 {
69 get
70 {
71 if (index >= Count)
72 {
73 throw new IndexOutOfRangeException();
74 }
76 return _events[index];
77 }
78 }
79
80 public virtual EventDescriptor? this[string name] => Find(name, ignoreCase: false);
81
82 bool ICollection.IsSynchronized => false;
83
84 object ICollection.SyncRoot => null;
85
86 int ICollection.Count => Count;
87
88 object? IList.this[int index]
89 {
90 get
91 {
92 return this[index];
93 }
94 set
95 {
96 if (_readOnly)
97 {
98 throw new NotSupportedException();
99 }
100 if (index >= Count)
101 {
102 throw new IndexOutOfRangeException();
103 }
106 }
107 }
108
109 bool IList.IsReadOnly => _readOnly;
110
111 bool IList.IsFixedSize => _readOnly;
112
114 {
115 if (events == null)
116 {
117 _events = Array.Empty<EventDescriptor>();
118 }
119 else
120 {
121 _events = events;
122 Count = events.Length;
123 }
124 _eventsOwned = true;
125 }
126
128 : this(events)
129 {
131 }
132
134 {
135 _eventsOwned = false;
136 if (namedSort != null)
137 {
138 _namedSort = (string[])namedSort.Clone();
139 }
141 _events = events;
143 _needSort = true;
144 }
145
147 {
148 if (_readOnly)
149 {
150 throw new NotSupportedException();
151 }
152 EnsureSize(Count + 1);
153 _events[Count++] = value;
154 return Count - 1;
155 }
156
157 public void Clear()
158 {
159 if (_readOnly)
160 {
161 throw new NotSupportedException();
162 }
163 Count = 0;
164 }
165
167 {
168 return IndexOf(value) >= 0;
169 }
170
176
177 private void EnsureEventsOwned()
178 {
179 if (!_eventsOwned)
180 {
181 _eventsOwned = true;
182 if (_events != null)
183 {
186 _events = array;
187 }
188 }
189 if (_needSort)
190 {
191 _needSort = false;
193 }
194 }
195
196 private void EnsureSize(int sizeNeeded)
197 {
198 if (sizeNeeded > _events.Length)
199 {
200 if (_events.Length == 0)
201 {
202 Count = 0;
204 return;
205 }
207 int num = Math.Max(sizeNeeded, _events.Length * 2);
210 _events = array;
211 }
212 }
213
214 public virtual EventDescriptor? Find(string name, bool ignoreCase)
215 {
216 EventDescriptor result = null;
217 if (ignoreCase)
218 {
219 for (int i = 0; i < Count; i++)
220 {
221 if (string.Equals(_events[i].Name, name, StringComparison.OrdinalIgnoreCase))
222 {
223 result = _events[i];
224 break;
225 }
226 }
227 }
228 else
229 {
230 for (int j = 0; j < Count; j++)
231 {
232 if (string.Equals(_events[j].Name, name, StringComparison.Ordinal))
233 {
234 result = _events[j];
235 break;
236 }
237 }
238 }
239 return result;
240 }
241
243 {
245 }
246
248 {
249 if (_readOnly)
250 {
251 throw new NotSupportedException();
252 }
253 EnsureSize(Count + 1);
254 if (index < Count)
255 {
257 }
259 Count++;
260 }
261
263 {
264 if (_readOnly)
265 {
266 throw new NotSupportedException();
267 }
268 int num = IndexOf(value);
269 if (num != -1)
270 {
271 RemoveAt(num);
272 }
273 }
274
275 public void RemoveAt(int index)
276 {
277 if (_readOnly)
278 {
279 throw new NotSupportedException();
280 }
281 if (index < Count - 1)
282 {
284 }
285 _events[Count - 1] = null;
286 Count--;
287 }
288
290 {
291 if (_events.Length == Count)
292 {
293 return _events.GetEnumerator();
294 }
296 }
297
302
303 public virtual EventDescriptorCollection Sort(string[] names)
304 {
306 }
307
312
317
318 protected void InternalSort(string[]? names)
319 {
320 if (_events.Length == 0)
321 {
322 return;
323 }
325 if (names == null || names.Length == 0)
326 {
327 return;
328 }
330 int num = 0;
331 int num2 = _events.Length;
332 for (int i = 0; i < names.Length; i++)
333 {
334 for (int j = 0; j < num2; j++)
335 {
337 if (eventDescriptor != null && eventDescriptor.Name.Equals(names[i]))
338 {
339 _events[num++] = eventDescriptor;
340 list[j] = null;
341 break;
342 }
343 }
344 }
345 for (int k = 0; k < num2; k++)
346 {
347 if (list[k] != null)
348 {
349 _events[num++] = list[k];
350 }
351 }
352 }
353
355 {
356 if (sorter == null)
357 {
359 }
360 else
361 {
363 }
364 }
365
370
371 int IList.Add(object value)
372 {
373 return Add((EventDescriptor)value);
374 }
375
376 bool IList.Contains(object value)
377 {
379 }
380
382 {
383 Clear();
384 }
385
386 int IList.IndexOf(object value)
387 {
389 }
390
391 void IList.Insert(int index, object value)
392 {
394 }
395
396 void IList.Remove(object value)
397 {
399 }
400
402 {
404 }
405}
static void Sort(Array array)
Definition Array.cs:2329
object? GetValue(params int[] indices)
Definition Array.cs:980
int IList. IndexOf(object value)
Definition Array.cs:1228
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
virtual EventDescriptorCollection Sort(string[] names, IComparer comparer)
EventDescriptorCollection(EventDescriptor[]? events, bool readOnly)
EventDescriptorCollection(EventDescriptor[] events, int eventCount, string[] namedSort, IComparer comparer)
virtual EventDescriptorCollection Sort(string[] names)
virtual EventDescriptorCollection Sort(IComparer comparer)
virtual ? EventDescriptor Find(string name, bool ignoreCase)
static void SortDescriptorArray(IList infos)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
void CopyTo(T[] array, int arrayIndex)
new IEnumerator< T > GetEnumerator()
void Insert(int index, T item)