Exemplo n.º 1
0
        static TResult[] ToArray <TSource, TResult>(this TSource[] source, Predicate <TSource> predicate, NullableSelector <TSource, TResult> selector, int skipCount, int takeCount)
        {
            var builder = new LargeArrayBuilder <TResult>(initialize: true);

            builder.AddRange <TSource>(source, predicate, selector, skipCount, takeCount);
            return(builder.ToArray());
        }
Exemplo n.º 2
0
        static TSource[] ToArray <TSource>(this TSource[] source, PredicateAt <TSource> predicate, int skipCount, int takeCount)
        {
            var builder = new LargeArrayBuilder <TSource>(initialize: true);

            builder.AddRange <TSource[]>(source, predicate, skipCount, takeCount);
            return(builder.ToArray());
        }
Exemplo n.º 3
0
        static TResult[] ToArray <TSource, TResult>(this ReadOnlySpan <TSource> source, Predicate <TSource> predicate, Selector <TSource, TResult> selector)
        {
            var builder = new LargeArrayBuilder <TResult>(initialize: true);

            builder.AddRange <TSource>(source, predicate, selector);
            return(builder.ToArray());
        }
Exemplo n.º 4
0
        static TSource[] ToArray <TSource>(this ReadOnlySpan <TSource> source, PredicateAt <TSource> predicate)
        {
            var builder = new LargeArrayBuilder <TSource>(initialize: true);

            builder.AddRange(source, predicate);
            return(builder.ToArray());
        }
Exemplo n.º 5
0
        static TSource[] ToArray <TList, TSource>(this TList source, PredicateAt <TSource> predicate, int skipCount, int takeCount)
            where TList : IReadOnlyList <TSource>
        {
            var builder = new LargeArrayBuilder <TSource>(initialize: true);

            builder.AddRange <TList>(source, predicate, skipCount, takeCount);
            return(builder.ToArray());
        }
Exemplo n.º 6
0
        static TResult[] ToArray <TList, TSource, TResult>(this TList source, Predicate <TSource> predicate, Selector <TSource, TResult> selector, int skipCount, int takeCount)
            where TList : notnull, IReadOnlyList <TSource>
        {
            var builder = new LargeArrayBuilder <TResult>(initialize: true);

            builder.AddRange <TList, TSource>(source, predicate, selector, skipCount, takeCount);
            return(builder.ToArray());
        }
        static TResult[] ToArray <TEnumerable, TEnumerator, TSource, TResult>(this TEnumerable source, Predicate <TSource> predicate, NullableSelector <TSource, TResult> selector)
            where TEnumerable : IValueEnumerable <TSource, TEnumerator>
            where TEnumerator : struct, IEnumerator <TSource>
        {
            var builder = new LargeArrayBuilder <TResult>(initialize: true);

            builder.AddRange <TEnumerable, TEnumerator, TSource>(source, predicate, selector);
            return(builder.ToArray());
        }
        static TSource[] ToArray <TEnumerable, TEnumerator, TSource>(this TEnumerable source, PredicateAt <TSource> predicate)
            where TEnumerable : IValueEnumerable <TSource, TEnumerator>
            where TEnumerator : struct, IEnumerator <TSource>
        {
            var builder = new LargeArrayBuilder <TSource>(initialize: true);

            builder.AddRange <TEnumerable, TEnumerator>(source, predicate);
            return(builder.ToArray());
        }
Exemplo n.º 9
0
        static T[] ToArray <T>(IEnumerable <T> source)
        {
            switch (source)
            {
            case ICollection <T> collection:
                var count = collection.Count;
                if (count == 0)
                {
                    return(System.Array.Empty <T>());
                }

                var buffer = new T[count];
                collection.CopyTo(buffer, 0);
                return(buffer);

            default:
                var builder = new LargeArrayBuilder <T>(initialize: true);
                builder.AddRange(source);
                return(builder.ToArray());
            }
        }
        public static TSource[] ToArray <TEnumerable, TEnumerator, TSource>(this TEnumerable source)
            where TEnumerable : IValueEnumerable <TSource, TEnumerator>
            where TEnumerator : struct, IEnumerator <TSource>
        {
            switch (source)
            {
            case ICollection <TSource> collection:
                var count = collection.Count;
                if (count == 0)
                {
                    return(Array.Empty <TSource>());
                }

                var buffer = new TSource[count];
                collection.CopyTo(buffer, 0);
                return(buffer);

            default:
                var builder = new LargeArrayBuilder <TSource>(initialize: true);
                builder.AddRange <TEnumerable, TEnumerator>(source);
                return(builder.ToArray());
            }
        }