<Compile Include="System\Linq\Distinct.cs" />
<Compile Include="System\Linq\ElementAt.cs" />
<Compile Include="System\Linq\Enumerable.cs" />
- <Compile Include="System\Linq\Errors.cs" />
<Compile Include="System\Linq\Except.cs" />
<Compile Include="System\Linq\First.cs" />
<Compile Include="System\Linq\Grouping.cs" />
<Compile Include="System\Linq\Skip.cs" />
<Compile Include="System\Linq\Sum.cs" />
<Compile Include="System\Linq\Take.cs" />
+ <Compile Include="System\Linq\ThrowHelper.cs" />
<Compile Include="System\Linq\ToCollection.cs" />
<Compile Include="System\Linq\Union.cs" />
<Compile Include="System\Linq\Utilities.cs" />
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (func == null)
{
- throw Error.ArgumentNull(nameof(func));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.func);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
TSource result = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (func == null)
{
- throw Error.ArgumentNull(nameof(func));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.func);
}
TAccumulate result = seed;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (func == null)
{
- throw Error.ArgumentNull(nameof(func));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.func);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
TAccumulate result = seed;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
foreach (TSource element in source)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
foreach (TSource element in source)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source is AppendPrependIterator<TSource> appendable
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source is AppendPrependIterator<TSource> appendable
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<int> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
long sum = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<int?> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<long> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
long sum = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<long?> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<float> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
double sum = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<float?> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<double> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
double sum = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<double?> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<decimal> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
decimal sum = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
using (IEnumerator<decimal?> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
long sum = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
long sum = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
double sum = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
double sum = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
decimal sum = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return OfTypeIterator<TResult>(source);
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return CastIterator<TResult>(source);
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return first is ConcatIterator<TSource> firstConcat
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (comparer == null)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is ICollection<TSource> collectionoft)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
int count = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long count = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
long count = 0;
{
public SystemCore_EnumerableDebugView(IEnumerable<T> enumerable)
{
- _enumerable = enumerable ?? throw Error.ArgumentNull(nameof(enumerable));
+ if (enumerable is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.enumerable);
+ }
+
+ _enumerable = enumerable;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
{
public SystemCore_EnumerableDebugView(IEnumerable enumerable)
{
- _enumerable = enumerable ?? throw Error.ArgumentNull(nameof(enumerable));
+ if (enumerable is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.enumerable);
+ }
+
+ _enumerable = enumerable;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return new DefaultIfEmptyIterator<TSource>(source, defaultValue);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return new DistinctIterator<TSource>(source, comparer);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IPartition<TSource> partition)
}
}
- throw Error.ArgumentOutOfRange(nameof(index));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
+ return default;
}
public static TSource ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IPartition<TSource> partition)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Linq
-{
- internal static class Error
- {
- internal static Exception ArgumentNull(string s) => new ArgumentNullException(s);
-
- internal static Exception ArgumentOutOfRange(string s) => new ArgumentOutOfRangeException(s);
-
- internal static Exception MoreThanOneElement() => new InvalidOperationException(SR.MoreThanOneElement);
-
- internal static Exception MoreThanOneMatch() => new InvalidOperationException(SR.MoreThanOneMatch);
-
- internal static Exception NoElements() => new InvalidOperationException(SR.NoElements);
-
- internal static Exception NoMatch() => new InvalidOperationException(SR.NoMatch);
-
- internal static Exception NotSupported() => new NotSupportedException();
- }
-}
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return ExceptIterator(first, second, null);
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return ExceptIterator(first, second, comparer);
TSource first = source.TryGetFirst(out bool found);
if (!found)
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
return first;
TSource first = source.TryGetFirst(predicate, out bool found);
if (!found)
{
- throw Error.NoMatch();
+ ThrowHelper.ThrowNoMatchException();
}
return first;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IPartition<TSource> partition)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
if (source is OrderedEnumerable<TSource> ordered)
{
if (outer == null)
{
- throw Error.ArgumentNull(nameof(outer));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outer);
}
if (inner == null)
{
- throw Error.ArgumentNull(nameof(inner));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.inner);
}
if (outerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(outerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outerKeySelector);
}
if (innerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(innerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.innerKeySelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return GroupJoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
{
if (outer == null)
{
- throw Error.ArgumentNull(nameof(outer));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outer);
}
if (inner == null)
{
- throw Error.ArgumentNull(nameof(inner));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.inner);
}
if (outerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(outerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outerKeySelector);
}
if (innerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(innerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.innerKeySelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return GroupJoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
bool ICollection<TElement>.IsReadOnly => true;
- void ICollection<TElement>.Add(TElement item) => throw Error.NotSupported();
+ void ICollection<TElement>.Add(TElement item) => ThrowHelper.ThrowNotSupportedException();
- void ICollection<TElement>.Clear() => throw Error.NotSupported();
+ void ICollection<TElement>.Clear() => ThrowHelper.ThrowNotSupportedException();
bool ICollection<TElement>.Contains(TElement item) => Array.IndexOf(_elements, item, 0, _count) >= 0;
void ICollection<TElement>.CopyTo(TElement[] array, int arrayIndex) =>
Array.Copy(_elements, 0, array, arrayIndex, _count);
- bool ICollection<TElement>.Remove(TElement item) => throw Error.NotSupported();
+ bool ICollection<TElement>.Remove(TElement item)
+ {
+ ThrowHelper.ThrowNotSupportedException();
+ return false;
+ }
int IList<TElement>.IndexOf(TElement item) => Array.IndexOf(_elements, item, 0, _count);
- void IList<TElement>.Insert(int index, TElement item) => throw Error.NotSupported();
+ void IList<TElement>.Insert(int index, TElement item) => ThrowHelper.ThrowNotSupportedException();
- void IList<TElement>.RemoveAt(int index) => throw Error.NotSupported();
+ void IList<TElement>.RemoveAt(int index) => ThrowHelper.ThrowNotSupportedException();
TElement IList<TElement>.this[int index]
{
{
if (index < 0 || index >= _count)
{
- throw Error.ArgumentOutOfRange(nameof(index));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
}
return _elements[index];
set
{
- throw Error.NotSupported();
+ ThrowHelper.ThrowNotSupportedException();
}
}
}
public GroupedResultEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
{
- _source = source ?? throw Error.ArgumentNull(nameof(source));
- _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
- _elementSelector = elementSelector ?? throw Error.ArgumentNull(nameof(elementSelector));
+ if (source is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
+ }
+ if (keySelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
+ }
+ if (elementSelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementSelector);
+ }
+ if (resultSelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
+ }
+
+ _source = source;
+ _keySelector = keySelector;
+ _elementSelector = elementSelector;
_comparer = comparer;
- _resultSelector = resultSelector ?? throw Error.ArgumentNull(nameof(resultSelector));
+ _resultSelector = resultSelector;
}
public IEnumerator<TResult> GetEnumerator()
public GroupedResultEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
{
- _source = source ?? throw Error.ArgumentNull(nameof(source));
- _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
- _resultSelector = resultSelector ?? throw Error.ArgumentNull(nameof(resultSelector));
+ if (source is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
+ }
+ if (keySelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
+ }
+ if (resultSelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
+ }
+
+ _source = source;
+ _keySelector = keySelector;
+ _resultSelector = resultSelector;
_comparer = comparer;
}
public GroupedEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
{
- _source = source ?? throw Error.ArgumentNull(nameof(source));
- _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
- _elementSelector = elementSelector ?? throw Error.ArgumentNull(nameof(elementSelector));
+ if (source is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
+ }
+ if (keySelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
+ }
+ if (elementSelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementSelector);
+ }
+
+ _source = source;
+ _keySelector = keySelector;
+ _elementSelector = elementSelector;
_comparer = comparer;
}
public GroupedEnumerable(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
- _source = source ?? throw Error.ArgumentNull(nameof(source));
- _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
+ if (source is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
+ }
+ if (keySelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
+ }
+
+ _source = source;
+ _keySelector = keySelector;
_comparer = comparer;
}
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return IntersectIterator(first, second, null);
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return IntersectIterator(first, second, comparer);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
- void IEnumerator.Reset() => throw Error.NotSupported();
+ void IEnumerator.Reset() => ThrowHelper.ThrowNotSupportedException();
}
}
}
{
if (outer == null)
{
- throw Error.ArgumentNull(nameof(outer));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outer);
}
if (inner == null)
{
- throw Error.ArgumentNull(nameof(inner));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.inner);
}
if (outerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(outerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outerKeySelector);
}
if (innerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(innerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.innerKeySelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return JoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
{
if (outer == null)
{
- throw Error.ArgumentNull(nameof(outer));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outer);
}
if (inner == null)
{
- throw Error.ArgumentNull(nameof(inner));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.inner);
}
if (outerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(outerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.outerKeySelector);
}
if (innerKeySelector == null)
{
- throw Error.ArgumentNull(nameof(innerKeySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.innerKeySelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return JoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
TSource last = source.TryGetLast(out bool found);
if (!found)
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
return last;
TSource last = source.TryGetLast(predicate, out bool found);
if (!found)
{
- throw Error.NoMatch();
+ ThrowHelper.ThrowNoMatchException();
}
return last;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IPartition<TSource> partition)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
if (source is OrderedEnumerable<TSource> ordered)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector == null)
{
- throw Error.ArgumentNull(nameof(keySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}
return Lookup<TKey, TSource>.Create(source, keySelector, comparer);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector == null)
{
- throw Error.ArgumentNull(nameof(keySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}
if (elementSelector == null)
{
- throw Error.ArgumentNull(nameof(elementSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementSelector);
}
return Lookup<TKey, TElement>.Create(source, keySelector, elementSelector, comparer);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
float value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
float? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
Comparer<TSource> comparer = Comparer<TSource>.Default;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
long value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
long? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
float value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
float? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
Comparer<TResult> comparer = Comparer<TResult>.Default;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
float value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
float? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
Comparer<TSource> comparer = Comparer<TSource>.Default;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = e.Current;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
long value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
long? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
float value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
float? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal value;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal? value = null;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
Comparer<TResult> comparer = Comparer<TResult>.Default;
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
value = selector(e.Current);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source.CreateOrderedEnumerable(keySelector, null, false);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source.CreateOrderedEnumerable(keySelector, comparer, false);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source.CreateOrderedEnumerable(keySelector, null, true);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source.CreateOrderedEnumerable(keySelector, comparer, true);
internal OrderedEnumerable(IEnumerable<TElement> source, Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending, OrderedEnumerable<TElement> parent)
{
- _source = source ?? throw Error.ArgumentNull(nameof(source));
+ if (source is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
+ }
+ if (keySelector is null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
+ }
+
+ _source = source;
_parent = parent;
- _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector));
+ _keySelector = keySelector;
_comparer = comparer ?? Comparer<TKey>.Default;
_descending = descending;
}
long max = ((long)start) + count - 1;
if (count < 0 || max > int.MaxValue)
{
- throw Error.ArgumentOutOfRange(nameof(count));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
}
if (count == 0)
{
if (count < 0)
{
- throw Error.ArgumentOutOfRange(nameof(count));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
}
if (count == 0)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return new ReverseIterator<TSource>(source);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
if (source is Iterator<TSource> iterator)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
return SelectIterator(source, selector);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
return new SelectManySingleSelectorIterator<TSource, TResult>(source, selector);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
return SelectManyIterator(source, selector);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (collectionSelector == null)
{
- throw Error.ArgumentNull(nameof(collectionSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collectionSelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return SelectManyIterator(source, collectionSelector, resultSelector);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (collectionSelector == null)
{
- throw Error.ArgumentNull(nameof(collectionSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collectionSelector);
}
if (resultSelector == null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return SelectManyIterator(source, collectionSelector, resultSelector);
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
if (first is ICollection<TSource> firstCol && second is ICollection<TSource> secondCol)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IList<TSource> list)
switch (list.Count)
{
case 0:
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
+ return default;
case 1:
return list[0];
}
{
if (!e.MoveNext())
{
- throw Error.NoElements();
+ ThrowHelper.ThrowNoElementsException();
}
TSource result = e.Current;
}
}
- throw Error.MoreThanOneElement();
+ ThrowHelper.ThrowMoreThanOneElementException();
+ return default;
}
public static TSource Single<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (predicate(e.Current))
{
- throw Error.MoreThanOneMatch();
+ ThrowHelper.ThrowMoreThanOneMatchException();
}
}
}
}
- throw Error.NoMatch();
+ ThrowHelper.ThrowNoMatchException();
+ return default;
}
public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (source is IList<TSource> list)
}
}
- throw Error.MoreThanOneElement();
+ ThrowHelper.ThrowMoreThanOneElementException();
+ return default;
}
public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
using (IEnumerator<TSource> e = source.GetEnumerator())
{
if (predicate(e.Current))
{
- throw Error.MoreThanOneMatch();
+ ThrowHelper.ThrowMoreThanOneMatchException();
}
}
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (count <= 0)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
return SkipWhileIterator(source, predicate);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
return SkipWhileIterator(source, predicate);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (count <= 0)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
int sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
decimal sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
int sum = 0;
{
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
long sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
long sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
double sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (selector == null)
{
- throw Error.ArgumentNull(nameof(selector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.selector);
}
decimal sum = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return count <= 0 ?
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
return TakeWhileIterator(source, predicate);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
return TakeWhileIterator(source, predicate);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return count <= 0 ?
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+namespace System.Linq
+{
+ internal static class ThrowHelper
+ {
+ internal static void ThrowArgumentNullException(ExceptionArgument argument) => throw new ArgumentNullException(GetArgumentString(argument));
+
+ internal static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) => throw new ArgumentOutOfRangeException(GetArgumentString(argument));
+
+ internal static void ThrowMoreThanOneElementException() => throw new InvalidOperationException(SR.MoreThanOneElement);
+
+ internal static void ThrowMoreThanOneMatchException() => throw new InvalidOperationException(SR.MoreThanOneMatch);
+
+ internal static void ThrowNoElementsException() => throw new InvalidOperationException(SR.NoElements);
+
+ internal static void ThrowNoMatchException() => throw new InvalidOperationException(SR.NoMatch);
+
+ internal static void ThrowNotSupportedException() => throw new NotSupportedException();
+
+ private static string GetArgumentString(ExceptionArgument argument)
+ {
+ switch (argument)
+ {
+ case ExceptionArgument.collectionSelector: return nameof(ExceptionArgument.collectionSelector);
+ case ExceptionArgument.count: return nameof(ExceptionArgument.count);
+ case ExceptionArgument.elementSelector: return nameof(ExceptionArgument.elementSelector);
+ case ExceptionArgument.enumerable: return nameof(ExceptionArgument.enumerable);
+ case ExceptionArgument.first: return nameof(ExceptionArgument.first);
+ case ExceptionArgument.func: return nameof(ExceptionArgument.func);
+ case ExceptionArgument.index: return nameof(ExceptionArgument.index);
+ case ExceptionArgument.inner: return nameof(ExceptionArgument.inner);
+ case ExceptionArgument.innerKeySelector: return nameof(ExceptionArgument.innerKeySelector);
+ case ExceptionArgument.keySelector: return nameof(ExceptionArgument.keySelector);
+ case ExceptionArgument.outer: return nameof(ExceptionArgument.outer);
+ case ExceptionArgument.outerKeySelector: return nameof(ExceptionArgument.outerKeySelector);
+ case ExceptionArgument.predicate: return nameof(ExceptionArgument.predicate);
+ case ExceptionArgument.resultSelector: return nameof(ExceptionArgument.resultSelector);
+ case ExceptionArgument.second: return nameof(ExceptionArgument.second);
+ case ExceptionArgument.selector: return nameof(ExceptionArgument.selector);
+ case ExceptionArgument.source: return nameof(ExceptionArgument.source);
+ default:
+ Debug.Fail("The ExceptionArgument value is not defined.");
+ return string.Empty;
+ }
+ }
+ }
+
+ internal enum ExceptionArgument
+ {
+ collectionSelector,
+ count,
+ elementSelector,
+ enumerable,
+ first,
+ func,
+ index,
+ inner,
+ innerKeySelector,
+ keySelector,
+ outer,
+ outerKeySelector,
+ predicate,
+ resultSelector,
+ second,
+ selector,
+ source,
+ }
+}
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source is IIListProvider<TSource> arrayProvider
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
return source is IIListProvider<TSource> listProvider ? listProvider.ToList() : new List<TSource>(source);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector == null)
{
- throw Error.ArgumentNull(nameof(keySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}
int capacity = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (keySelector == null)
{
- throw Error.ArgumentNull(nameof(keySelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keySelector);
}
if (elementSelector == null)
{
- throw Error.ArgumentNull(nameof(elementSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementSelector);
}
int capacity = 0;
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
// Don't pre-allocate based on knowledge of size, as potentially many elements will be dropped.
{
if (first == null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second == null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
return first is UnionIterator<TSource> union && AreEqualityComparersEqual(comparer, union._comparer) ? union.Union(second) : new UnionIterator2<TSource>(first, second, comparer);
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
if (source is Iterator<TSource> iterator)
{
if (source == null)
{
- throw Error.ArgumentNull(nameof(source));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
- throw Error.ArgumentNull(nameof(predicate));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
return WhereIterator(source, predicate);
{
if (first is null)
{
- throw Error.ArgumentNull(nameof(first));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);
}
if (second is null)
{
- throw Error.ArgumentNull(nameof(second));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);
}
if (resultSelector is null)
{
- throw Error.ArgumentNull(nameof(resultSelector));
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.resultSelector);
}
return ZipIterator(first, second, resultSelector);