Exemplo n.º 1
0
 public static void OutOfRange(int paramValue, int maxValue, /*[CallerArgumentExpression("paramValue")]*/ string paramName)
 {
     if ((uint)paramValue >= (uint)maxValue)
     {
         Throw.ArgumentOutOfRangeException(paramName);
     }
 }
        static TSource ElementAt <TList, TSource>(this TList source, int index, int skipCount, int takeCount)
            where TList : notnull, IReadOnlyList <TSource>
        {
            var item = TryElementAt <TList, TSource>(source, index, skipCount, takeCount);

            return(item.HasValue
                ? item.Value
                : Throw.ArgumentOutOfRangeException <TSource>(nameof(index)));
        }
Exemplo n.º 3
0
        public static RepeatEnumerable <TSource> Repeat <TSource>(TSource value, int count)
        {
            if (count < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(count));
            }

            return(new RepeatEnumerable <TSource>(value, count));
        }
Exemplo n.º 4
0
            public readonly TSource this[int index]
            {
                get
                {
                    if (index < 0 || index >= Count)
                    {
                        Throw.ArgumentOutOfRangeException(nameof(index));
                    }

                    return(source[index + skipCount]);
                }
            }
Exemplo n.º 5
0
        public static RangeEnumerable Range(int start, int count)
        {
            if (count < 0)
            {
                Throw.ArgumentOutOfRangeException(nameof(count));
            }

            try
            {
                _ = checked (start + count);
            }
            catch (OverflowException)
            {
                Throw.ArgumentOutOfRangeException(nameof(count));
            }

            return(new RangeEnumerable(start, count));
        }
        public static TSource ElementAt <TEnumerable, TEnumerator, TSource>(this TEnumerable source, int index)
            where TEnumerable : notnull, IValueReadOnlyCollection <TSource, TEnumerator>
            where TEnumerator : struct, IEnumerator <TSource>
        {
            if (index >= 0 && index < source.Count)
            {
                using var enumerator = source.GetEnumerator();
                for (; enumerator.MoveNext(); index--)
                {
                    if (index == 0)
                    {
                        return(enumerator.Current);
                    }
                }
            }

            return(Throw.ArgumentOutOfRangeException <TSource>(nameof(index)));
        }
        public static async ValueTask <TSource> ElementAtAsync <TEnumerable, TEnumerator, TSource>(this TEnumerable source, int index, CancellationToken cancellationToken = default)
            where TEnumerable : notnull, IAsyncValueEnumerable <TSource, TEnumerator>
            where TEnumerator : struct, IAsyncEnumerator <TSource>
        {
            if (index >= 0)
            {
                var enumerator = source.GetAsyncEnumerator(cancellationToken);
                await using (enumerator.ConfigureAwait(false))
                {
                    for (; await enumerator.MoveNextAsync().ConfigureAwait(false); index--)
                    {
                        if (index == 0)
                        {
                            return(enumerator.Current);
                        }
                    }
                }
            }

            return(Throw.ArgumentOutOfRangeException <TSource>(nameof(index)));
        }
Exemplo n.º 8
0
 public     TSource this[int index]
 => Throw.ArgumentOutOfRangeException <TSource>(nameof(index));