Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ImmutableArrayExtensions.cs
Go to the documentation of this file.
3
4namespace System.Linq;
5
6public static class ImmutableArrayExtensions
7{
9 {
10 immutableArray.ThrowNullRefIfNotInitialized();
11 return immutableArray.array.Select(selector);
12 }
13
15 {
16 immutableArray.ThrowNullRefIfNotInitialized();
17 if (collectionSelector == null || resultSelector == null)
18 {
20 }
21 if (immutableArray.Length != 0)
22 {
23 return immutableArray.SelectManyIterator(collectionSelector, resultSelector);
24 }
25 return Enumerable.Empty<TResult>();
26 }
27
29 {
30 immutableArray.ThrowNullRefIfNotInitialized();
31 return immutableArray.array.Where(predicate);
32 }
33
34 public static bool Any<T>(this ImmutableArray<T> immutableArray)
35 {
36 return immutableArray.Length > 0;
37 }
38
40 {
41 immutableArray.ThrowNullRefIfNotInitialized();
42 Requires.NotNull(predicate, "predicate");
43 T[] array = immutableArray.array;
44 foreach (T arg in array)
45 {
46 if (predicate(arg))
47 {
48 return true;
49 }
50 }
51 return false;
52 }
53
55 {
56 immutableArray.ThrowNullRefIfNotInitialized();
57 Requires.NotNull(predicate, "predicate");
58 T[] array = immutableArray.array;
59 foreach (T arg in array)
60 {
61 if (!predicate(arg))
62 {
63 return false;
64 }
65 }
66 return true;
67 }
68
70 {
71 immutableArray.ThrowNullRefIfNotInitialized();
72 items.ThrowNullRefIfNotInitialized();
73 if (immutableArray.array == items.array)
74 {
75 return true;
76 }
77 if (immutableArray.Length != items.Length)
78 {
79 return false;
80 }
81 if (comparer == null)
82 {
84 }
85 for (int i = 0; i < immutableArray.Length; i++)
86 {
87 if (!comparer.Equals(immutableArray.array[i], (TBase)(object)items.array[i]))
88 {
89 return false;
90 }
91 }
92 return true;
93 }
94
96 {
97 Requires.NotNull(items, "items");
98 if (comparer == null)
99 {
101 }
102 int num = 0;
103 int length = immutableArray.Length;
104 foreach (TDerived item in items)
105 {
106 if (num == length)
107 {
108 return false;
109 }
110 if (!comparer.Equals(immutableArray[num], (TBase)(object)item))
111 {
112 return false;
113 }
114 num++;
115 }
116 return num == length;
117 }
118
120 {
121 Requires.NotNull(predicate, "predicate");
122 immutableArray.ThrowNullRefIfNotInitialized();
123 items.ThrowNullRefIfNotInitialized();
124 if (immutableArray.array == items.array)
125 {
126 return true;
127 }
128 if (immutableArray.Length != items.Length)
129 {
130 return false;
131 }
132 int i = 0;
133 for (int length = immutableArray.Length; i < length; i++)
134 {
135 if (!predicate(immutableArray[i], (TBase)(object)items[i]))
136 {
137 return false;
138 }
139 }
140 return true;
141 }
142
144 {
145 Requires.NotNull(func, "func");
146 if (immutableArray.Length == 0)
147 {
148 return default(T);
149 }
150 T val = immutableArray[0];
151 int i = 1;
152 for (int length = immutableArray.Length; i < length; i++)
153 {
154 val = func(val, immutableArray[i]);
155 }
156 return val;
157 }
158
160 {
161 Requires.NotNull(func, "func");
162 TAccumulate val = seed;
163 T[] array = immutableArray.array;
164 foreach (T arg in array)
165 {
166 val = func(val, arg);
167 }
168 return val;
169 }
170
176
178 {
179 return immutableArray[index];
180 }
181
183 {
185 {
186 return default(T);
187 }
188 return immutableArray[index];
189 }
190
192 {
193 Requires.NotNull(predicate, "predicate");
194 T[] array = immutableArray.array;
195 foreach (T val in array)
196 {
197 if (predicate(val))
198 {
199 return val;
200 }
201 }
202 return Enumerable.Empty<T>().First();
203 }
204
206 {
207 if (immutableArray.Length <= 0)
208 {
209 return immutableArray.array.First();
210 }
211 return immutableArray[0];
212 }
213
215 {
216 if (immutableArray.array.Length == 0)
217 {
218 return default(T);
219 }
220 return immutableArray.array[0];
221 }
222
224 {
225 Requires.NotNull(predicate, "predicate");
226 T[] array = immutableArray.array;
227 foreach (T val in array)
228 {
229 if (predicate(val))
230 {
231 return val;
232 }
233 }
234 return default(T);
235 }
236
238 {
239 if (immutableArray.Length <= 0)
240 {
241 return immutableArray.array.Last();
242 }
243 return immutableArray[immutableArray.Length - 1];
244 }
245
247 {
248 Requires.NotNull(predicate, "predicate");
249 for (int num = immutableArray.Length - 1; num >= 0; num--)
250 {
251 if (predicate(immutableArray[num]))
252 {
253 return immutableArray[num];
254 }
255 }
256 return Enumerable.Empty<T>().Last();
257 }
258
260 {
261 immutableArray.ThrowNullRefIfNotInitialized();
262 return immutableArray.array.LastOrDefault();
263 }
264
266 {
267 Requires.NotNull(predicate, "predicate");
268 for (int num = immutableArray.Length - 1; num >= 0; num--)
269 {
270 if (predicate(immutableArray[num]))
271 {
272 return immutableArray[num];
273 }
274 }
275 return default(T);
276 }
277
279 {
280 immutableArray.ThrowNullRefIfNotInitialized();
281 return immutableArray.array.Single();
282 }
283
285 {
286 Requires.NotNull(predicate, "predicate");
287 bool flag = true;
288 T result = default(T);
289 T[] array = immutableArray.array;
290 foreach (T val in array)
291 {
292 if (predicate(val))
293 {
294 if (!flag)
295 {
297 }
298 flag = false;
299 result = val;
300 }
301 }
302 if (flag)
303 {
304 Enumerable.Empty<T>().Single();
305 }
306 return result;
307 }
308
310 {
311 immutableArray.ThrowNullRefIfNotInitialized();
312 return immutableArray.array.SingleOrDefault();
313 }
314
316 {
317 Requires.NotNull(predicate, "predicate");
318 bool flag = true;
319 T result = default(T);
320 T[] array = immutableArray.array;
321 foreach (T val in array)
322 {
323 if (predicate(val))
324 {
325 if (!flag)
326 {
328 }
329 flag = false;
330 result = val;
331 }
332 }
333 return result;
334 }
335
340
345
358
371
373 {
374 immutableArray.ThrowNullRefIfNotInitialized();
375 if (immutableArray.array.Length == 0)
376 {
377 return ImmutableArray<T>.Empty.array;
378 }
379 return (T[])immutableArray.array.Clone();
380 }
381
382 public static T First<T>(this ImmutableArray<T>.Builder builder)
383 {
384 Requires.NotNull(builder, "builder");
385 if (!builder.Any())
386 {
387 throw new InvalidOperationException();
388 }
389 return builder[0];
390 }
391
392 public static T? FirstOrDefault<T>(this ImmutableArray<T>.Builder builder)
393 {
394 Requires.NotNull(builder, "builder");
395 if (!builder.Any())
396 {
397 return default(T);
398 }
399 return builder[0];
400 }
401
402 public static T Last<T>(this ImmutableArray<T>.Builder builder)
403 {
404 Requires.NotNull(builder, "builder");
405 if (!builder.Any())
406 {
407 throw new InvalidOperationException();
408 }
409 return builder[builder.Count - 1];
410 }
411
412 public static T? LastOrDefault<T>(this ImmutableArray<T>.Builder builder)
413 {
414 Requires.NotNull(builder, "builder");
415 if (!builder.Any())
416 {
417 return default(T);
418 }
419 return builder[builder.Count - 1];
420 }
421
422 public static bool Any<T>(this ImmutableArray<T>.Builder builder)
423 {
424 Requires.NotNull(builder, "builder");
425 return builder.Count > 0;
426 }
427
439}
void Add(TKey key, TValue value)
static IEnumerable< TResult > Select< T, TResult >(this ImmutableArray< T > immutableArray, Func< T, TResult > selector)
static ? T ElementAtOrDefault< T >(this ImmutableArray< T > immutableArray, int index)
static bool Any< T >(this ImmutableArray< T > immutableArray)
static ? T Aggregate< T >(this ImmutableArray< T > immutableArray, Func< T, T, T > func)
static ? T SingleOrDefault< T >(this ImmutableArray< T > immutableArray)
static T[] ToArray< T >(this ImmutableArray< T > immutableArray)
static T First< T >(this ImmutableArray< T > immutableArray, Func< T, bool > predicate)
static bool All< T >(this ImmutableArray< T > immutableArray, Func< T, bool > predicate)
static T Single< T >(this ImmutableArray< T > immutableArray)
static TAccumulate Aggregate< TAccumulate, T >(this ImmutableArray< T > immutableArray, TAccumulate seed, Func< TAccumulate, T, TAccumulate > func)
static ? T FirstOrDefault< T >(this ImmutableArray< T > immutableArray)
static IEnumerable< T > Where< T >(this ImmutableArray< T > immutableArray, Func< T, bool > predicate)
static TResult Aggregate< TAccumulate, TResult, T >(this ImmutableArray< T > immutableArray, TAccumulate seed, Func< TAccumulate, T, TAccumulate > func, Func< TAccumulate, TResult > resultSelector)
static bool SequenceEqual< TDerived, TBase >(this ImmutableArray< TBase > immutableArray, ImmutableArray< TDerived > items, IEqualityComparer< TBase >? comparer=null)
static Dictionary< TKey, T > ToDictionary< TKey, T >(this ImmutableArray< T > immutableArray, Func< T, TKey > keySelector)
static IEnumerable< TResult > SelectMany< TSource, TCollection, TResult >(this ImmutableArray< TSource > immutableArray, Func< TSource, IEnumerable< TCollection > > collectionSelector, Func< TSource, TCollection, TResult > resultSelector)
static IEnumerable< TResult > SelectManyIterator< TSource, TCollection, TResult >(this ImmutableArray< TSource > immutableArray, Func< TSource, IEnumerable< TCollection > > collectionSelector, Func< TSource, TCollection, TResult > resultSelector)
static T Last< T >(this ImmutableArray< T > immutableArray)
static ? T LastOrDefault< T >(this ImmutableArray< T > immutableArray)
static Dictionary< TKey, TElement > ToDictionary< TKey, TElement, T >(this ImmutableArray< T > immutableArray, Func< T, TKey > keySelector, Func< T, TElement > elementSelector)
static T ElementAt< T >(this ImmutableArray< T > immutableArray, int index)