-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtilities.cs
More file actions
24 lines (24 loc) · 894 Bytes
/
Utilities.cs
File metadata and controls
24 lines (24 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
namespace MTLib;
public static class Utilities {
private static readonly HashSet<Type> ValTupleTypes = new([
typeof(ValueTuple<>), typeof(ValueTuple<,>),
typeof(ValueTuple<,,>), typeof(ValueTuple<,,,>),
typeof(ValueTuple<,,,,>), typeof(ValueTuple<,,,,,>),
typeof(ValueTuple<,,,,,,>), typeof(ValueTuple<,,,,,,,>) ]
);
public static Boolean IsObjectTuple(Object obj) {
ArgumentNullException.ThrowIfNull(obj);
var type = obj.GetType();
return (type.IsGenericType && ValTupleTypes.Contains(
type.GetGenericTypeDefinition()
));
}
public static IEnumerable<Object?> GetValuesFromTuple(
System.Runtime.CompilerServices.ITuple tuple
) {
ArgumentNullException.ThrowIfNull(tuple);
for (Int32 i = 0; i < tuple.Length; i++) {
yield return tuple[i];
}
}
}