DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.7.3" />

.NET API 552,344 bytes

 TupleExtensions

public static class TupleExtensions
Provides extension methods for tuples.
using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext { [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] public static class TupleExtensions { [System.Runtime.CompilerServices.NullableContext(1)] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] public static object[] ToArray<T>(this T tuple) where T : ITuple { object[] array; if (tuple.Length > 0) { array = new object[tuple.Length]; for (int i = 0; i < array.Length; i++) { array[i] = tuple[i]; } } else array = Array.Empty<object>(); return array; } private static Span<T> TupleToSpan<T, TTuple>(ref TTuple tuple) where TTuple : struct, ITuple { return MemoryMarshal.CreateSpan(ref Unsafe.As<TTuple, T>(ref tuple), tuple.Length); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>(ref ValueTuple tuple) { return Span<T>.Empty; } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] ref ValueTuple tuple) { return ReadOnlySpan<T>.Empty; } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] ref ValueTuple<T> tuple) { return TupleToSpan<T, ValueTuple<T>>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] ref ValueTuple<T> tuple) { return TupleToSpan<T, ValueTuple<T>>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1 })] ref(T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1 })] ref(T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T)>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1 })] ref(T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1 })] ref(T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T)>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1 })] ref(T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1 })] ref(T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T)>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T)>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T, T)>(ref Unsafe.AsRef(ref tuple)); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static Span<T> AsSpan<T>([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T, T, T)>(ref tuple); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan<T> AsReadOnlySpan<T>([In] [IsReadOnly] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1, 1, 1, 1, 1 })] ref(T, T, T, T, T, T, T) tuple) { return TupleExtensions.TupleToSpan<T, (T, T, T, T, T, T, T)>(ref Unsafe.AsRef(ref tuple)); } } }