-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathArrayUtils.cs
44 lines (38 loc) · 831 Bytes
/
ArrayUtils.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
using System;
namespace GameDevWare.Dynamic.Expressions
{
internal static class ArrayUtils
{
private class EmptyArray<T>
{
public static T[] Value = new T[0];
}
public static ResultT[] ConvertAll<T, ResultT>(this T[] array,
#if NETSTANDARD
Func<T, ResultT> converter
#else
Converter<T, ResultT> converter
#endif
)
{
if (array == null) throw new ArgumentNullException("array");
if (converter == null) throw new ArgumentNullException("converter");
#if NETSTANDARD
var result = new ResultT[array.Length];
for (var i = 0; i < array.Length; i++)
result[i] = converter(array[i]);
return result;
#else
return Array.ConvertAll(array, converter);
#endif
}
public static T[] Empty<T>()
{
#if NETCOREAPP
return Array.Empty<T>();
#else
return EmptyArray<T>.Value;
#endif
}
}
}