Switch LINQ over to using ThrowHelper pattern (dotnet/corefx#35213)
authorStephen Toub <stoub@microsoft.com>
Mon, 11 Feb 2019 21:28:51 +0000 (16:28 -0500)
committerGitHub <noreply@github.com>
Mon, 11 Feb 2019 21:28:51 +0000 (16:28 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/8750960d3fafa46a9b838c351e995a01fa8b599f

42 files changed:
src/libraries/System.Linq/src/System.Linq.csproj
src/libraries/System.Linq/src/System/Linq/Aggregate.cs
src/libraries/System.Linq/src/System/Linq/AnyAll.cs
src/libraries/System.Linq/src/System/Linq/AppendPrepend.cs
src/libraries/System.Linq/src/System/Linq/Average.cs
src/libraries/System.Linq/src/System/Linq/Cast.cs
src/libraries/System.Linq/src/System/Linq/Concat.cs
src/libraries/System.Linq/src/System/Linq/Contains.cs
src/libraries/System.Linq/src/System/Linq/Count.cs
src/libraries/System.Linq/src/System/Linq/DebugView.cs
src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs
src/libraries/System.Linq/src/System/Linq/Distinct.cs
src/libraries/System.Linq/src/System/Linq/ElementAt.cs
src/libraries/System.Linq/src/System/Linq/Errors.cs [deleted file]
src/libraries/System.Linq/src/System/Linq/Except.cs
src/libraries/System.Linq/src/System/Linq/First.cs
src/libraries/System.Linq/src/System/Linq/GroupJoin.cs
src/libraries/System.Linq/src/System/Linq/Grouping.cs
src/libraries/System.Linq/src/System/Linq/Intersect.cs
src/libraries/System.Linq/src/System/Linq/Iterator.cs
src/libraries/System.Linq/src/System/Linq/Join.cs
src/libraries/System.Linq/src/System/Linq/Last.cs
src/libraries/System.Linq/src/System/Linq/Lookup.cs
src/libraries/System.Linq/src/System/Linq/Max.cs
src/libraries/System.Linq/src/System/Linq/Min.cs
src/libraries/System.Linq/src/System/Linq/OrderBy.cs
src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs
src/libraries/System.Linq/src/System/Linq/Range.cs
src/libraries/System.Linq/src/System/Linq/Repeat.cs
src/libraries/System.Linq/src/System/Linq/Reverse.cs
src/libraries/System.Linq/src/System/Linq/Select.cs
src/libraries/System.Linq/src/System/Linq/SelectMany.cs
src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs
src/libraries/System.Linq/src/System/Linq/Single.cs
src/libraries/System.Linq/src/System/Linq/Skip.cs
src/libraries/System.Linq/src/System/Linq/Sum.cs
src/libraries/System.Linq/src/System/Linq/Take.cs
src/libraries/System.Linq/src/System/Linq/ThrowHelper.cs [new file with mode: 0644]
src/libraries/System.Linq/src/System/Linq/ToCollection.cs
src/libraries/System.Linq/src/System/Linq/Union.cs
src/libraries/System.Linq/src/System/Linq/Where.cs
src/libraries/System.Linq/src/System/Linq/Zip.cs

index 49b0cb7..f41e961 100644 (file)
@@ -71,7 +71,6 @@
     <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" />
@@ -99,6 +98,7 @@
     <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" />
index 121ad6d..c0461f0 100644 (file)
@@ -12,19 +12,19 @@ namespace System.Linq
         {
             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;
@@ -41,12 +41,12 @@ namespace System.Linq
         {
             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;
@@ -62,17 +62,17 @@ namespace System.Linq
         {
             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;
index a99ecf6..3bbb730 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<TSource> e = source.GetEnumerator())
@@ -25,12 +25,12 @@ namespace System.Linq
         {
             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)
@@ -48,12 +48,12 @@ namespace System.Linq
         {
             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)
index bc7282c..a9bf0a6 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source is AppendPrependIterator<TSource> appendable
@@ -25,7 +25,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source is AppendPrependIterator<TSource> appendable
index a9ef6d3..5d26c5e 100644 (file)
@@ -12,14 +12,14 @@ namespace System.Linq
         {
             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;
@@ -41,7 +41,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<int?> e = source.GetEnumerator())
@@ -78,14 +78,14 @@ namespace System.Linq
         {
             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;
@@ -107,7 +107,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<long?> e = source.GetEnumerator())
@@ -144,14 +144,14 @@ namespace System.Linq
         {
             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;
@@ -170,7 +170,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<float?> e = source.GetEnumerator())
@@ -207,14 +207,14 @@ namespace System.Linq
         {
             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;
@@ -236,7 +236,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<double?> e = source.GetEnumerator())
@@ -273,14 +273,14 @@ namespace System.Linq
         {
             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;
@@ -299,7 +299,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             using (IEnumerator<decimal?> e = source.GetEnumerator())
@@ -333,19 +333,19 @@ namespace System.Linq
         {
             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);
@@ -367,12 +367,12 @@ namespace System.Linq
         {
             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())
@@ -409,19 +409,19 @@ namespace System.Linq
         {
             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);
@@ -443,12 +443,12 @@ namespace System.Linq
         {
             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())
@@ -485,19 +485,19 @@ namespace System.Linq
         {
             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);
@@ -516,12 +516,12 @@ namespace System.Linq
         {
             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())
@@ -558,19 +558,19 @@ namespace System.Linq
         {
             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);
@@ -592,12 +592,12 @@ namespace System.Linq
         {
             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())
@@ -634,19 +634,19 @@ namespace System.Linq
         {
             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);
@@ -665,12 +665,12 @@ namespace System.Linq
         {
             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())
index 4190ad3..fca2f51 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return OfTypeIterator<TResult>(source);
@@ -40,7 +40,7 @@ namespace System.Linq
             
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
             
             return CastIterator<TResult>(source);
index 694b762..6c0aaaa 100644 (file)
@@ -13,12 +13,12 @@ namespace System.Linq
         {
             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
index eb0e1ce..12df4ca 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (comparer == null)
index 01434cb..45521cb 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (source is ICollection<TSource> collectionoft)
@@ -50,12 +50,12 @@ namespace System.Linq
         {
             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;
@@ -77,7 +77,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long count = 0;
@@ -99,12 +99,12 @@ namespace System.Linq
         {
             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;
index 1957cd9..79dadce 100644 (file)
@@ -24,7 +24,12 @@ namespace System.Linq
     {
         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)]
@@ -55,7 +60,12 @@ namespace System.Linq
     {
         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)]
index 8011d54..1c38075 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return new DefaultIfEmptyIterator<TSource>(source, defaultValue);
index 72b3952..0cca724 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return new DistinctIterator<TSource>(source, comparer);
index 75f37df..9c47ee8 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (source is IPartition<TSource> partition)
@@ -47,14 +47,15 @@ namespace System.Linq
                 }
             }
 
-            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)
diff --git a/src/libraries/System.Linq/src/System/Linq/Errors.cs b/src/libraries/System.Linq/src/System/Linq/Errors.cs
deleted file mode 100644 (file)
index 8c2c2a9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// 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();
-    }
-}
index f1b4e1c..e30b074 100644 (file)
@@ -12,12 +12,12 @@ namespace System.Linq
         {
             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);
@@ -27,12 +27,12 @@ namespace System.Linq
         {
             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);
index 190ba96..41e7b13 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
             TSource first = source.TryGetFirst(out bool found);
             if (!found)
             {
-                throw Error.NoElements();
+                ThrowHelper.ThrowNoElementsException();
             }
 
             return first;
@@ -24,7 +24,7 @@ namespace System.Linq
             TSource first = source.TryGetFirst(predicate, out bool found);
             if (!found)
             {
-                throw Error.NoMatch();
+                ThrowHelper.ThrowNoMatchException();
             }
 
             return first;
@@ -40,7 +40,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (source is IPartition<TSource> partition)
@@ -76,12 +76,12 @@ namespace System.Linq
         {
             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)
index cc9afd5..f5eb350 100644 (file)
@@ -12,27 +12,27 @@ namespace System.Linq
         {
             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);
@@ -42,27 +42,27 @@ namespace System.Linq
         {
             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);
index 76660e4..1c43581 100644 (file)
@@ -98,22 +98,26 @@ namespace System.Linq
 
         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]
         {
@@ -121,7 +125,7 @@ namespace System.Linq
             {
                 if (index < 0 || index >= _count)
                 {
-                    throw Error.ArgumentOutOfRange(nameof(index));
+                    ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index);
                 }
 
                 return _elements[index];
@@ -129,7 +133,7 @@ namespace System.Linq
 
             set
             {
-                throw Error.NotSupported();
+                ThrowHelper.ThrowNotSupportedException();
             }
         }
     }
@@ -144,11 +148,28 @@ namespace System.Linq
 
         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()
@@ -169,9 +190,22 @@ namespace System.Linq
 
         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;
         }
 
@@ -193,9 +227,22 @@ namespace System.Linq
 
         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;
         }
 
@@ -213,8 +260,17 @@ namespace System.Linq
 
         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;
         }
 
index 2e2cd2d..d83b9c3 100644 (file)
@@ -12,12 +12,12 @@ namespace System.Linq
         {
             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);
@@ -27,12 +27,12 @@ namespace System.Linq
         {
             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);
index 76466e6..c99066c 100644 (file)
@@ -113,7 +113,7 @@ namespace System.Linq
 
             IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
 
-            void IEnumerator.Reset() => throw Error.NotSupported();
+            void IEnumerator.Reset() => ThrowHelper.ThrowNotSupportedException();
         }
     }
 }
index e9e900f..3f0a7d9 100644 (file)
@@ -12,27 +12,27 @@ namespace System.Linq
         {
             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);
@@ -42,27 +42,27 @@ namespace System.Linq
         {
             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);
index c6be8e1..bb25495 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
             TSource last = source.TryGetLast(out bool found);
             if (!found)
             {
-                throw Error.NoElements();
+                ThrowHelper.ThrowNoElementsException();
             }
 
             return last;
@@ -24,7 +24,7 @@ namespace System.Linq
             TSource last = source.TryGetLast(predicate, out bool found);
             if (!found)
             {
-                throw Error.NoMatch();
+                ThrowHelper.ThrowNoMatchException();
             }
 
             return last;
@@ -40,7 +40,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (source is IPartition<TSource> partition)
@@ -84,12 +84,12 @@ namespace System.Linq
         {
             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)
index c4f5d15..b0169e5 100644 (file)
@@ -17,12 +17,12 @@ namespace System.Linq
         {
             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);
@@ -35,17 +35,17 @@ namespace System.Linq
         {
             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);
index 5a15ae0..c2fc7f5 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int value;
@@ -20,7 +20,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -41,7 +41,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int? value = null;
@@ -103,7 +103,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long value;
@@ -111,7 +111,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -132,7 +132,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long? value = null;
@@ -188,7 +188,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double value;
@@ -196,7 +196,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -232,7 +232,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double? value = null;
@@ -286,7 +286,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             float value;
@@ -294,7 +294,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -325,7 +325,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             float? value = null;
@@ -379,7 +379,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal value;
@@ -387,7 +387,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -408,7 +408,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal? value = null;
@@ -445,7 +445,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             Comparer<TSource> comparer = Comparer<TSource>.Default;
@@ -481,7 +481,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
                     }
 
                     value = e.Current;
@@ -503,12 +503,12 @@ namespace System.Linq
         {
             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;
@@ -516,7 +516,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -537,12 +537,12 @@ namespace System.Linq
         {
             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;
@@ -604,12 +604,12 @@ namespace System.Linq
         {
             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;
@@ -617,7 +617,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -638,12 +638,12 @@ namespace System.Linq
         {
             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;
@@ -699,12 +699,12 @@ namespace System.Linq
         {
             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;
@@ -712,7 +712,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -743,12 +743,12 @@ namespace System.Linq
         {
             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;
@@ -802,12 +802,12 @@ namespace System.Linq
         {
             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;
@@ -815,7 +815,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -851,12 +851,12 @@ namespace System.Linq
         {
             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;
@@ -910,12 +910,12 @@ namespace System.Linq
         {
             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;
@@ -923,7 +923,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -944,12 +944,12 @@ namespace System.Linq
         {
             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;
@@ -986,12 +986,12 @@ namespace System.Linq
         {
             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;
@@ -1027,7 +1027,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
                     }
 
                     value = selector(e.Current);
index 4249a84..97f942f 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int value;
@@ -20,7 +20,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -41,7 +41,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int? value = null;
@@ -85,7 +85,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long value;
@@ -93,7 +93,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -114,7 +114,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long? value = null;
@@ -154,7 +154,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             float value;
@@ -162,7 +162,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -196,7 +196,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             float? value = null;
@@ -240,7 +240,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double value;
@@ -248,7 +248,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -273,7 +273,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double? value = null;
@@ -317,7 +317,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal value;
@@ -325,7 +325,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = e.Current;
@@ -346,7 +346,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal? value = null;
@@ -383,7 +383,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             Comparer<TSource> comparer = Comparer<TSource>.Default;
@@ -419,7 +419,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
                     }
 
                     value = e.Current;
@@ -441,12 +441,12 @@ namespace System.Linq
         {
             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;
@@ -454,7 +454,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -475,12 +475,12 @@ namespace System.Linq
         {
             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;
@@ -524,12 +524,12 @@ namespace System.Linq
         {
             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;
@@ -537,7 +537,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -558,12 +558,12 @@ namespace System.Linq
         {
             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;
@@ -603,12 +603,12 @@ namespace System.Linq
         {
             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;
@@ -616,7 +616,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -650,12 +650,12 @@ namespace System.Linq
         {
             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;
@@ -699,12 +699,12 @@ namespace System.Linq
         {
             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;
@@ -712,7 +712,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -737,12 +737,12 @@ namespace System.Linq
         {
             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;
@@ -786,12 +786,12 @@ namespace System.Linq
         {
             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;
@@ -799,7 +799,7 @@ namespace System.Linq
             {
                 if (!e.MoveNext())
                 {
-                    throw Error.NoElements();
+                    ThrowHelper.ThrowNoElementsException();
                 }
 
                 value = selector(e.Current);
@@ -820,12 +820,12 @@ namespace System.Linq
         {
             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;
@@ -862,12 +862,12 @@ namespace System.Linq
         {
             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;
@@ -903,7 +903,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
                     }
 
                     value = selector(e.Current);
index b2dbbf0..9c9a77b 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source.CreateOrderedEnumerable(keySelector, null, false);
@@ -34,7 +34,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source.CreateOrderedEnumerable(keySelector, comparer, false);
@@ -44,7 +44,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source.CreateOrderedEnumerable(keySelector, null, true);
@@ -54,7 +54,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source.CreateOrderedEnumerable(keySelector, comparer, true);
index 0500b71..54d13f8 100644 (file)
@@ -145,9 +145,18 @@ namespace System.Linq
 
         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;
         }
index 1260a1f..a26ed82 100644 (file)
@@ -14,7 +14,7 @@ namespace System.Linq
             long max = ((long)start) + count - 1;
             if (count < 0 || max > int.MaxValue)
             {
-                throw Error.ArgumentOutOfRange(nameof(count));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
             }
 
             if (count == 0)
index 8ffa47a..76e2ce4 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (count < 0)
             {
-                throw Error.ArgumentOutOfRange(nameof(count));
+                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count);
             }
 
             if (count == 0)
index 29ae52b..3c12002 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return new ReverseIterator<TSource>(source);
index 942d075..2cccaf0 100644 (file)
@@ -15,12 +15,12 @@ namespace System.Linq
         {
             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)
@@ -65,12 +65,12 @@ namespace System.Linq
         {
             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);
index 75ca930..2ef2e3d 100644 (file)
@@ -13,12 +13,12 @@ namespace System.Linq
         {
             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);
@@ -28,12 +28,12 @@ namespace System.Linq
         {
             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);
@@ -60,17 +60,17 @@ namespace System.Linq
         {
             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);
@@ -97,17 +97,17 @@ namespace System.Linq
         {
             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);
index df8600f..262a118 100644 (file)
@@ -20,12 +20,12 @@ namespace System.Linq
 
             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)
index 3874f81..fdeb9ce 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (source is IList<TSource> list)
@@ -20,7 +20,8 @@ namespace System.Linq
                 switch (list.Count)
                 {
                     case 0:
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
+                        return default;
                     case 1:
                         return list[0];
                 }
@@ -31,7 +32,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        throw Error.NoElements();
+                        ThrowHelper.ThrowNoElementsException();
                     }
 
                     TSource result = e.Current;
@@ -42,19 +43,20 @@ namespace System.Linq
                 }
             }
 
-            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())
@@ -68,7 +70,7 @@ namespace System.Linq
                         {
                             if (predicate(e.Current))
                             {
-                                throw Error.MoreThanOneMatch();
+                                ThrowHelper.ThrowMoreThanOneMatchException();
                             }
                         }
 
@@ -77,14 +79,15 @@ namespace System.Linq
                 }
             }
 
-            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)
@@ -114,19 +117,20 @@ namespace System.Linq
                 }
             }
 
-            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())
@@ -140,7 +144,7 @@ namespace System.Linq
                         {
                             if (predicate(e.Current))
                             {
-                                throw Error.MoreThanOneMatch();
+                                ThrowHelper.ThrowMoreThanOneMatchException();
                             }
                         }
 
index 99bd870..bf854ee 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (count <= 0)
@@ -39,12 +39,12 @@ namespace System.Linq
         {
             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);
@@ -75,12 +75,12 @@ namespace System.Linq
         {
             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);
@@ -117,7 +117,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             if (count <= 0)
index 3c29a26..74eb73e 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int sum = 0;
@@ -31,7 +31,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             int sum = 0;
@@ -53,7 +53,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long sum = 0;
@@ -72,7 +72,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             long sum = 0;
@@ -94,7 +94,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double sum = 0;
@@ -110,7 +110,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double sum = 0;
@@ -129,7 +129,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double sum = 0;
@@ -145,7 +145,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             double sum = 0;
@@ -164,7 +164,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal sum = 0;
@@ -180,7 +180,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             decimal sum = 0;
@@ -199,12 +199,12 @@ namespace System.Linq
         {
             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;
@@ -223,12 +223,12 @@ namespace System.Linq
         {
             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;
@@ -251,12 +251,12 @@ namespace System.Linq
         {
             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;
@@ -275,12 +275,12 @@ namespace System.Linq
         {
             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;
@@ -303,12 +303,12 @@ namespace System.Linq
         {
             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;
@@ -324,12 +324,12 @@ namespace System.Linq
         {
             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;
@@ -349,12 +349,12 @@ namespace System.Linq
         {
             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;
@@ -370,12 +370,12 @@ namespace System.Linq
         {
             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;
@@ -395,12 +395,12 @@ namespace System.Linq
         {
             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;
@@ -416,12 +416,12 @@ namespace System.Linq
         {
             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;
index ce5d201..0f67ef6 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return count <= 0 ?
@@ -25,12 +25,12 @@ namespace System.Linq
         {
             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);
@@ -53,12 +53,12 @@ namespace System.Linq
         {
             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);
@@ -87,7 +87,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return count <= 0 ?
diff --git a/src/libraries/System.Linq/src/System/Linq/ThrowHelper.cs b/src/libraries/System.Linq/src/System/Linq/ThrowHelper.cs
new file mode 100644 (file)
index 0000000..e39381b
--- /dev/null
@@ -0,0 +1,74 @@
+// 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,
+    }
+}
index 0ed6184..d6ad500 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source is IIListProvider<TSource> arrayProvider
@@ -24,7 +24,7 @@ namespace System.Linq
         {
             if (source == null)
             {
-                throw Error.ArgumentNull(nameof(source));
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
             }
 
             return source is IIListProvider<TSource> listProvider ? listProvider.ToList() : new List<TSource>(source);
@@ -37,12 +37,12 @@ namespace System.Linq
         {
             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;
@@ -103,17 +103,17 @@ namespace System.Linq
         {
             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;
@@ -173,7 +173,7 @@ namespace System.Linq
         {
             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.
index a63121e..f4a5d9d 100644 (file)
@@ -16,12 +16,12 @@ namespace System.Linq
         {
             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);
index fe63843..80c8a01 100644 (file)
@@ -14,12 +14,12 @@ namespace System.Linq
         {
             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)
@@ -46,12 +46,12 @@ namespace System.Linq
         {
             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);
index c49337c..19c4dd4 100644 (file)
@@ -12,17 +12,17 @@ namespace System.Linq
         {
             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);