From f329683555acce14b8bdb79f197c4b7924f56046 Mon Sep 17 00:00:00 2001 From: Bart De Smet Date: Sat, 25 May 2019 03:31:54 -0700 Subject: [PATCH] Enable nullable reference types. --- Ix.NET/Source/AsyncQueryableGenerator.t4 | 2 +- .../System.Interactive.Async.Providers.csproj | 5 + .../System/Linq/AsyncQueryableEx.Generated.cs | 30 +-- .../System/Linq/AsyncQueryableEx.Generated.tt | 7 +- .../System.Interactive.Async.csproj | 1 + .../System/Linq/Operators/Amb.cs | 10 +- .../System/Linq/Operators/Catch.cs | 8 +- .../System/Linq/Operators/Distinct.cs | 48 ++-- .../Linq/Operators/DistinctUntilChanged.cs | 30 ++- .../System/Linq/Operators/Do.cs | 6 +- .../System/Linq/Operators/Max.cs | 4 +- .../System/Linq/Operators/MaxBy.cs | 12 +- .../System/Linq/Operators/Merge.cs | 4 +- .../System/Linq/Operators/Min.cs | 4 +- .../System/Linq/Operators/MinBy.cs | 10 +- .../System/Linq/Operators/Never.cs | 8 +- .../Linq/Operators/OnErrorResumeNext.cs | 7 +- .../System/Linq/Operators/Return.cs | 2 +- .../System/Linq/Operators/Throw.cs | 2 +- .../System/Linq/Operators/Timeout.cs | 6 +- .../System.Linq.Async.Queryable.csproj | 1 + .../System/Linq/AsyncEnumerableExecutor.cs | 2 +- .../System/Linq/AsyncEnumerableQuery.cs | 7 +- .../System/Linq/AsyncEnumerableRewriter.cs | 8 +- .../System/Linq/AsyncQueryable.Generated.cs | 98 ++++---- .../System/Linq/AsyncQueryable.Generated.tt | 5 +- .../System.Linq.Async.csproj | 1 + .../System/Linq/AsyncEnumerableHelpers.cs | 2 +- .../System/Linq/AsyncEnumerablePartition.cs | 6 +- .../System/Linq/AsyncEnumerator.cs | 2 +- .../System/Linq/AsyncIterator.cs | 4 +- .../System/Linq/Disposables.cs | 6 +- .../System/Linq/IOrderedAsyncEnumerable.cs | 6 +- .../System/Linq/Operators/AppendPrepend.cs | 16 +- .../System/Linq/Operators/Concat.cs | 12 +- .../System/Linq/Operators/Contains.cs | 2 +- .../System/Linq/Operators/DefaultIfEmpty.cs | 6 +- .../System/Linq/Operators/Distinct.cs | 14 +- .../Linq/Operators/ElementAtOrDefault.cs | 2 +- .../System/Linq/Operators/Empty.cs | 2 +- .../System/Linq/Operators/Except.cs | 2 +- .../System/Linq/Operators/FirstOrDefault.cs | 8 +- .../System/Linq/Operators/GroupBy.cs | 144 +++++------ .../System/Linq/Operators/GroupJoin.cs | 6 +- .../System/Linq/Operators/Grouping.cs | 10 +- .../System/Linq/Operators/Intersect.cs | 2 +- .../System/Linq/Operators/Join.cs | 12 +- .../System/Linq/Operators/LastOrDefault.cs | 24 +- .../System/Linq/Operators/Lookup.cs | 226 ++++++++++-------- .../System/Linq/Operators/Max.cs | 32 +-- .../System/Linq/Operators/Min.cs | 32 +-- .../Linq/Operators/OrderedAsyncEnumerable.cs | 65 ++--- .../System/Linq/Operators/Reverse.cs | 4 +- .../System/Linq/Operators/Select.cs | 24 +- .../System/Linq/Operators/SelectMany.cs | 24 +- .../System/Linq/Operators/SequenceEqual.cs | 2 +- .../System/Linq/Operators/SingleLinkedNode.cs | 10 +- .../System/Linq/Operators/SingleOrDefault.cs | 18 +- .../Operators/ToAsyncEnumerable.Observable.cs | 17 +- .../Linq/Operators/ToAsyncEnumerable.cs | 12 +- .../System/Linq/Operators/ToDictionary.cs | 24 +- .../System/Linq/Operators/ToEnumerable.cs | 4 +- .../System/Linq/Operators/ToHashSet.cs | 4 +- .../System/Linq/Operators/ToLookup.cs | 24 +- .../System/Linq/Operators/Union.cs | 28 +-- .../System/Linq/Operators/Where.cs | 16 +- .../System.Linq.Async/System/Linq/Set.cs | 4 +- 67 files changed, 612 insertions(+), 574 deletions(-) diff --git a/Ix.NET/Source/AsyncQueryableGenerator.t4 b/Ix.NET/Source/AsyncQueryableGenerator.t4 index 04c4412019..d1de3d45f4 100644 --- a/Ix.NET/Source/AsyncQueryableGenerator.t4 +++ b/Ix.NET/Source/AsyncQueryableGenerator.t4 @@ -154,7 +154,7 @@ foreach (var m in asyncEnumerableType.GetMethods() } } - var pars = string.Join(", ", m.GetParameters().Select((p, i) => (i == parCount - 1 && isParams ? "params " : "") + toQuoted(p.ParameterType, i) + " " + p.Name + (i == parCount - 1 && lastParameterDefault ? " = default" : ""))); + var pars = string.Join(", ", m.GetParameters().Select((p, i) => (i == parCount - 1 && isParams ? "params " : "") + toQuoted(p.ParameterType, i) + (nullableParameterNames.Contains(p.Name) ? "?" : "") + " " + p.Name + (i == parCount - 1 && lastParameterDefault ? " = default" : ""))); var quotedPars = string.Join(", ", m.GetParameters().Select((p, i) => "default(" + toQuoted(p.ParameterType, i) + ")")); if (m.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), true)) diff --git a/Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj b/Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj index 95296f404d..ac09bd2634 100644 --- a/Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj +++ b/Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.csproj @@ -5,6 +5,7 @@ Interactive Extensions - Async Providers Library net461;netstandard2.0;netstandard2.1;netcoreapp3.0 Ix;Interactive;Extensions;Enumerable;Asynchronous + enable @@ -21,4 +22,8 @@ + + + + diff --git a/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs b/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs index 3a19d17011..8829586610 100644 --- a/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs +++ b/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs @@ -188,7 +188,7 @@ private static MethodInfo Distinct__TSource_TKey__3__0(Type TSource, Type TKey) (s_Distinct__TSource_TKey__3__0 ?? (s_Distinct__TSource_TKey__3__0 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>(Distinct).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -204,7 +204,7 @@ private static MethodInfo Distinct__TSource_TKey__3__1(Type TSource, Type TKey) (s_Distinct__TSource_TKey__3__1 ?? (s_Distinct__TSource_TKey__3__1 = new Func, Expression>, IEqualityComparer, IAsyncQueryable>(Distinct).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -220,7 +220,7 @@ private static MethodInfo Distinct__TSource_TKey__3__2(Type TSource, Type TKey) (s_Distinct__TSource_TKey__3__2 ?? (s_Distinct__TSource_TKey__3__2 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>(Distinct).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable Distinct(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -250,7 +250,7 @@ private static MethodInfo DistinctUntilChanged__TSource__2__0(Type TSource) => (s_DistinctUntilChanged__TSource__2__0 ?? (s_DistinctUntilChanged__TSource__2__0 = new Func, IEqualityComparer, IAsyncQueryable>(DistinctUntilChanged).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, IEqualityComparer comparer) + public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -312,7 +312,7 @@ private static MethodInfo DistinctUntilChanged__TSource_TKey__3__0(Type TSource, (s_DistinctUntilChanged__TSource_TKey__3__0 ?? (s_DistinctUntilChanged__TSource_TKey__3__0 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>(DistinctUntilChanged).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -328,7 +328,7 @@ private static MethodInfo DistinctUntilChanged__TSource_TKey__3__1(Type TSource, (s_DistinctUntilChanged__TSource_TKey__3__1 ?? (s_DistinctUntilChanged__TSource_TKey__3__1 = new Func, Expression>, IEqualityComparer, IAsyncQueryable>(DistinctUntilChanged).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -344,7 +344,7 @@ private static MethodInfo DistinctUntilChanged__TSource_TKey__3__2(Type TSource, (s_DistinctUntilChanged__TSource_TKey__3__2 ?? (s_DistinctUntilChanged__TSource_TKey__3__2 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>(DistinctUntilChanged).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable DistinctUntilChanged(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -700,7 +700,7 @@ private static MethodInfo MaxAsync__TSource__3__0(Type TSource) => (s_MaxAsync__TSource__3__0 ?? (s_MaxAsync__TSource__3__0 = new Func, IComparer, CancellationToken, ValueTask>(MaxAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static ValueTask MaxAsync(this IAsyncQueryable source, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask MaxAsync(this IAsyncQueryable source, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -762,7 +762,7 @@ private static MethodInfo MaxByAsync__TSource_TKey__4__0(Type TSource, Type TKey (s_MaxByAsync__TSource_TKey__4__0 ?? (s_MaxByAsync__TSource_TKey__4__0 = new Func, Expression>>, IComparer, CancellationToken, ValueTask>>(MaxByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -778,7 +778,7 @@ private static MethodInfo MaxByAsync__TSource_TKey__4__1(Type TSource, Type TKey (s_MaxByAsync__TSource_TKey__4__1 ?? (s_MaxByAsync__TSource_TKey__4__1 = new Func, Expression>, IComparer, CancellationToken, ValueTask>>(MaxByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -794,7 +794,7 @@ private static MethodInfo MaxByAsync__TSource_TKey__4__2(Type TSource, Type TKey (s_MaxByAsync__TSource_TKey__4__2 ?? (s_MaxByAsync__TSource_TKey__4__2 = new Func, Expression>>, IComparer, CancellationToken, ValueTask>>(MaxByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -824,7 +824,7 @@ private static MethodInfo MinAsync__TSource__3__0(Type TSource) => (s_MinAsync__TSource__3__0 ?? (s_MinAsync__TSource__3__0 = new Func, IComparer, CancellationToken, ValueTask>(MinAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static ValueTask MinAsync(this IAsyncQueryable source, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask MinAsync(this IAsyncQueryable source, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -886,7 +886,7 @@ private static MethodInfo MinByAsync__TSource_TKey__4__0(Type TSource, Type TKey (s_MinByAsync__TSource_TKey__4__0 ?? (s_MinByAsync__TSource_TKey__4__0 = new Func, Expression>>, IComparer, CancellationToken, ValueTask>>(MinByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -902,7 +902,7 @@ private static MethodInfo MinByAsync__TSource_TKey__4__1(Type TSource, Type TKey (s_MinByAsync__TSource_TKey__4__1 ?? (s_MinByAsync__TSource_TKey__4__1 = new Func, Expression>, IComparer, CancellationToken, ValueTask>>(MinByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -918,7 +918,7 @@ private static MethodInfo MinByAsync__TSource_TKey__4__2(Type TSource, Type TKey (s_MinByAsync__TSource_TKey__4__2 ?? (s_MinByAsync__TSource_TKey__4__2 = new Func, Expression>>, IComparer, CancellationToken, ValueTask>>(MinByAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MinByAsync(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); diff --git a/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt b/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt index 2580817564..ec0dca12cf 100644 --- a/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt +++ b/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.tt @@ -3,9 +3,10 @@ // See the LICENSE file in the project root for more information. <#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Threading.Tasks.Extensions.dll" #> -<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Linq.Async.dll" #> -<#@ assembly name="$(ProjectDir)\..\System.Interactive.Async\bin\$(Configuration)\net46\System.Interactive.Async.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\Microsoft.Bcl.AsyncInterfaces.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Threading.Tasks.Extensions.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Linq.Async.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Interactive.Async\bin\$(Configuration)\net461\System.Interactive.Async.dll" #> <#@ output extension=".cs" #> <# var asyncEnumerableType = typeof(AsyncEnumerableEx); diff --git a/Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj b/Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj index 3209f92736..d29c0ae7ec 100644 --- a/Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj +++ b/Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.csproj @@ -5,6 +5,7 @@ Interactive Extensions - Async Library net461;netstandard2.0;netstandard2.1;netcoreapp3.0 Ix;Interactive;Extensions;Enumerable;Asynchronous + enable diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs index 0de698fa22..849a41f8f5 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs @@ -21,11 +21,11 @@ public static IAsyncEnumerable Amb(this IAsyncEnumerable Core(CancellationToken cancellationToken) { - IAsyncEnumerator firstEnumerator = null; - IAsyncEnumerator secondEnumerator = null; + IAsyncEnumerator? firstEnumerator = null; + IAsyncEnumerator? secondEnumerator = null; - Task firstMoveNext = null; - Task secondMoveNext = null; + Task? firstMoveNext = null; + Task? secondMoveNext = null; try { @@ -228,7 +228,7 @@ public static IAsyncEnumerable Amb(this IEnumerable(Task moveNextAsync, IAsyncEnumerator enumerator) + private static async Task AwaitMoveNextAsyncAndDispose(Task? moveNextAsync, IAsyncEnumerator? enumerator) { if (enumerator != null) { diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs index 958ec44ba9..16cca4faea 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs @@ -41,7 +41,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) { while (true) { - var c = default(TSource); + TSource c; try { @@ -95,7 +95,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) { while (true) { - var c = default(TSource); + TSource c; try { @@ -150,7 +150,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) { while (true) { - var c = default(TSource); + TSource c; try { @@ -222,7 +222,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) while (true) { - var c = default(TSource); + TSource c; try { diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs index c062547f33..aad57802b0 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Distinct.cs @@ -21,7 +21,7 @@ public static IAsyncEnumerable Distinct(this IAsyncEnume return DistinctCore(source, keySelector, comparer: null); } - public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -53,7 +53,7 @@ public static IAsyncEnumerable Distinct(this IAsyncEnume } #endif - public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -64,7 +64,7 @@ public static IAsyncEnumerable Distinct(this IAsyncEnume } #if !NO_DEEP_CANCELLATION - public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -75,18 +75,18 @@ public static IAsyncEnumerable Distinct(this IAsyncEnume } #endif - private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { return new DistinctAsyncIterator(source, keySelector, comparer); } - private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { return new DistinctAsyncIteratorWithTask(source, keySelector, comparer); } #if !NO_DEEP_CANCELLATION - private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { return new DistinctAsyncIteratorWithTaskAndCancellation(source, keySelector, comparer); } @@ -94,14 +94,14 @@ private static IAsyncEnumerable DistinctCore(IAsyncEnume private sealed class DistinctAsyncIterator : AsyncIterator, IAsyncIListProvider { - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; private readonly Func _keySelector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; - private Set _set; + private IAsyncEnumerator? _enumerator; + private Set? _set; - public DistinctAsyncIterator(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + public DistinctAsyncIterator(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -194,11 +194,11 @@ protected override async ValueTask MoveNextCore() return true; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { element = _enumerator.Current; - if (_set.Add(_keySelector(element))) + if (_set!.Add(_keySelector(element))) { _current = element; return true; @@ -242,14 +242,14 @@ private async Task> FillSetAsync(CancellationToken cancellationTok private sealed class DistinctAsyncIteratorWithTask : AsyncIterator, IAsyncIListProvider { - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; private readonly Func> _keySelector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; - private Set _set; + private IAsyncEnumerator? _enumerator; + private Set? _set; - public DistinctAsyncIteratorWithTask(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public DistinctAsyncIteratorWithTask(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -342,11 +342,11 @@ protected override async ValueTask MoveNextCore() return true; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { element = _enumerator.Current; - if (_set.Add(await _keySelector(element).ConfigureAwait(false))) + if (_set!.Add(await _keySelector(element).ConfigureAwait(false))) { _current = element; return true; @@ -391,14 +391,14 @@ private async ValueTask> FillSetAsync(CancellationToken cancellati #if !NO_DEEP_CANCELLATION private sealed class DistinctAsyncIteratorWithTaskAndCancellation : AsyncIterator, IAsyncIListProvider { - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; private readonly Func> _keySelector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; - private Set _set; + private IAsyncEnumerator? _enumerator; + private Set? _set; - public DistinctAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public DistinctAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -491,11 +491,11 @@ protected override async ValueTask MoveNextCore() return true; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { element = _enumerator.Current; - if (_set.Add(await _keySelector(element, _cancellationToken).ConfigureAwait(false))) + if (_set!.Add(await _keySelector(element, _cancellationToken).ConfigureAwait(false))) { _current = element; return true; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs index 5767001fc0..bdc17195bf 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs @@ -18,7 +18,7 @@ public static IAsyncEnumerable DistinctUntilChanged(this IAsyn return DistinctUntilChangedCore(source, comparer: null); } - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, IEqualityComparer comparer) + public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -36,7 +36,7 @@ public static IAsyncEnumerable DistinctUntilChanged(this return DistinctUntilChangedCore(source, keySelector, comparer: null); } - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -68,7 +68,7 @@ public static IAsyncEnumerable DistinctUntilChanged(this } #endif - public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public static IAsyncEnumerable DistinctUntilChanged(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -90,7 +90,7 @@ public static IAsyncEnumerable DistinctUntilChanged(this } #endif - private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, IEqualityComparer? comparer) { comparer ??= EqualityComparer.Default; @@ -113,7 +113,9 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) { var item = e.Current; - if (!comparer.Equals(latest, item)) + // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings. + + if (!comparer!.Equals(latest, item)) { latest = item; @@ -124,7 +126,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) } } - private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { comparer ??= EqualityComparer.Default; @@ -151,7 +153,9 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var currentKey = keySelector(item); - if (!comparer.Equals(latestKey, currentKey)) + // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings. + + if (!comparer!.Equals(latestKey, currentKey)) { latestKey = currentKey; @@ -162,7 +166,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) } } - private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { comparer ??= EqualityComparer.Default; @@ -189,7 +193,9 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var currentKey = await keySelector(item).ConfigureAwait(false); - if (!comparer.Equals(latestKey, currentKey)) + // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings. + + if (!comparer!.Equals(latestKey, currentKey)) { latestKey = currentKey; @@ -201,7 +207,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) } #if !NO_DEEP_CANCELLATION - private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + private static IAsyncEnumerable DistinctUntilChangedCore(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { comparer ??= EqualityComparer.Default; @@ -228,7 +234,9 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var currentKey = await keySelector(item, cancellationToken).ConfigureAwait(false); - if (!comparer.Equals(latestKey, currentKey)) + // REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings. + + if (!comparer!.Equals(latestKey, currentKey)) { latestKey = currentKey; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs index 00262e9ec9..22f035fec0 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Do.cs @@ -168,7 +168,7 @@ public static IAsyncEnumerable Do(this IAsyncEnumerable(observer.OnNext), new Action(observer.OnError), new Action(observer.OnCompleted)); } - private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Action onNext, Action onError, Action onCompleted) + private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Action onNext, Action? onError, Action? onCompleted) { return AsyncEnumerable.Create(Core); @@ -209,7 +209,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) } } - private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Func onNext, Func onError, Func onCompleted) + private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Func onNext, Func? onError, Func? onCompleted) { return AsyncEnumerable.Create(Core); @@ -254,7 +254,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) } #if !NO_DEEP_CANCELLATION - private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Func onNext, Func onError, Func onCompleted) + private static IAsyncEnumerable DoCore(IAsyncEnumerable source, Func onNext, Func? onError, Func? onCompleted) { return AsyncEnumerable.Create(Core); diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs index 0da8ec2eb6..6470781532 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Max.cs @@ -10,14 +10,14 @@ namespace System.Linq { public static partial class AsyncEnumerableEx { - public static ValueTask MaxAsync(this IAsyncEnumerable source, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask MaxAsync(this IAsyncEnumerable source, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); return Core(source, comparer, cancellationToken); - static async ValueTask Core(IAsyncEnumerable source, IComparer comparer, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs index a6ef7ef46b..6097525d08 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MaxBy.cs @@ -20,7 +20,7 @@ public static ValueTask> MaxByAsync(this IAsyncEnu return MaxByCore(source, keySelector, comparer: null, cancellationToken); } - public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -52,7 +52,7 @@ public static ValueTask> MaxByAsync(this IAsyncEnu } #endif - public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -63,7 +63,7 @@ public static ValueTask> MaxByAsync(this IAsyncEnu } #if !NO_DEEP_CANCELLATION - public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MaxByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -74,14 +74,14 @@ public static ValueTask> MaxByAsync(this IAsyncEnu } #endif - private static ValueTask> MaxByCore(IAsyncEnumerable source, Func keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MaxByCore(IAsyncEnumerable source, Func keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; return ExtremaBy(source, keySelector, (key, minValue) => comparer.Compare(key, minValue), cancellationToken); } - private static ValueTask> MaxByCore(IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MaxByCore(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; @@ -89,7 +89,7 @@ private static ValueTask> MaxByCore(IAsyncEnumerab } #if !NO_DEEP_CANCELLATION - private static ValueTask> MaxByCore(IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MaxByCore(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs index f51855ae20..1273619bd2 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Merge.cs @@ -176,7 +176,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) { var count = sources.Length; - var enumerators = new IAsyncEnumerator[count]; + var enumerators = new IAsyncEnumerator?[count]; var moveNextTasks = new Task[count]; try @@ -212,7 +212,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var index = Array.IndexOf(moveNextTasks, moveNextTask); - var enumerator = enumerators[index]; + var enumerator = enumerators[index]!; // NB: Only gets set to null after setting task to Never. if (!await moveNextTask.ConfigureAwait(false)) { diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs index 362cbd4a4e..7c86ce8302 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Min.cs @@ -10,14 +10,14 @@ namespace System.Linq { public static partial class AsyncEnumerableEx { - public static ValueTask MinAsync(this IAsyncEnumerable source, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask MinAsync(this IAsyncEnumerable source, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); return Core(source, comparer, cancellationToken); - static async ValueTask Core(IAsyncEnumerable source, IComparer comparer, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs index 6c467168c2..75398e47b2 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/MinBy.cs @@ -20,7 +20,7 @@ public static ValueTask> MinByAsync(this IAsyncEnu return MinByCore(source, keySelector, comparer: null, cancellationToken); } - public static ValueTask> MinByAsync(this IAsyncEnumerable source, Func keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MinByAsync(this IAsyncEnumerable source, Func keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -52,7 +52,7 @@ public static ValueTask> MinByAsync(this IAsyncEnu } #endif - public static ValueTask> MinByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> MinByAsync(this IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -74,14 +74,14 @@ public static ValueTask> MinByAsync(this IAsyncEnu } #endif - private static ValueTask> MinByCore(IAsyncEnumerable source, Func keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MinByCore(IAsyncEnumerable source, Func keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; return ExtremaBy(source, keySelector, (key, minValue) => -comparer.Compare(key, minValue), cancellationToken); } - private static ValueTask> MinByCore(IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MinByCore(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; @@ -89,7 +89,7 @@ private static ValueTask> MinByCore(IAsyncEnumerab } #if !NO_DEEP_CANCELLATION - private static ValueTask> MinByCore(IAsyncEnumerable source, Func> keySelector, IComparer comparer, CancellationToken cancellationToken) + private static ValueTask> MinByCore(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, CancellationToken cancellationToken) { comparer ??= Comparer.Default; diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs index c20d01d014..cdc81ba038 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Never.cs @@ -29,7 +29,6 @@ private sealed class NeverAsyncEnumerator : IAsyncEnumerator private CancellationTokenRegistration _registration; private bool _once; - private TaskCompletionSource _task; public NeverAsyncEnumerator(CancellationToken token) => _token = token; @@ -38,7 +37,6 @@ private sealed class NeverAsyncEnumerator : IAsyncEnumerator public ValueTask DisposeAsync() { _registration.Dispose(); - _task = null; return default; } @@ -50,9 +48,9 @@ public ValueTask MoveNextAsync() } _once = true; - _task = new TaskCompletionSource(); - _registration = _token.Register(state => ((NeverAsyncEnumerator)state)._task.SetCanceled(), this); - return new ValueTask(_task.Task); + var task = new TaskCompletionSource(); + _registration = _token.Register(state => ((TaskCompletionSource)state).SetCanceled(), task); + return new ValueTask(task.Task); } } } diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs index 6b928fd772..6a3825e689 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/OnErrorResumeNext.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Diagnostics; -using System.Threading; using System.Threading.Tasks; namespace System.Linq @@ -46,8 +45,8 @@ private sealed class OnErrorResumeNextAsyncIterator : AsyncIterator> _sources; - private IAsyncEnumerator _enumerator; - private IEnumerator> _sourcesEnumerator; + private IAsyncEnumerator? _enumerator; + private IEnumerator>? _sourcesEnumerator; public OnErrorResumeNextAsyncIterator(IEnumerable> sources) { @@ -93,7 +92,7 @@ protected override async ValueTask MoveNextCore() { if (_enumerator == null) { - if (!_sourcesEnumerator.MoveNext()) + if (!_sourcesEnumerator!.MoveNext()) { break; // while -- done, nothing else to do } diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs index 2c5e864fe3..e8d7621d1c 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs @@ -43,7 +43,7 @@ private sealed class ReturnEnumerator : IAsyncEnumerator public ValueTask DisposeAsync() { - Current = default; + Current = default!; return default; } diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs index aecc4352da..be4b6603f7 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Throw.cs @@ -51,7 +51,7 @@ public ThrowEnumerator(ValueTask moveNextThrows) _moveNextThrows = moveNextThrows; } - public TValue Current => default; + public TValue Current => default!; public ValueTask DisposeAsync() { diff --git a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs index ff56076096..287003b607 100644 --- a/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs +++ b/Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Timeout.cs @@ -28,9 +28,9 @@ private sealed class TimeoutAsyncIterator : AsyncIterator private readonly IAsyncEnumerable _source; private readonly TimeSpan _timeout; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; - private Task _loserTask; + private Task? _loserTask; public TimeoutAsyncIterator(IAsyncEnumerable source, TimeSpan timeout) { @@ -73,7 +73,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - var moveNext = _enumerator.MoveNextAsync(); + var moveNext = _enumerator!.MoveNextAsync(); if (!moveNext.IsCompleted) { diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj b/Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj index 4d3f12d038..2d669c4126 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System.Linq.Async.Queryable.csproj @@ -2,6 +2,7 @@ net461;netstandard2.0;netstandard2.1;netcoreapp3.0 + enable diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs index ab5bce51b5..0164a8e630 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableExecutor.cs @@ -15,7 +15,7 @@ namespace System.Linq internal class AsyncEnumerableExecutor { private readonly Expression _expression; - private Func> _func; + private Func>? _func; /// /// Creates a new execution helper instance for the specified expression tree representing a computation over asynchronous enumerable sequences. diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs index 5e6898187b..b8a7fd0dd8 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq.Expressions; -using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -18,7 +17,7 @@ internal abstract class AsyncEnumerableQuery /// /// Gets the enumerable sequence obtained from evaluating the expression tree. /// - internal abstract object Enumerable { get; } + internal abstract object? Enumerable { get; } /// /// Gets the expression tree representing the asynchronous enumerable sequence. @@ -33,7 +32,7 @@ internal abstract class AsyncEnumerableQuery internal class AsyncEnumerableQuery : AsyncEnumerableQuery, IOrderedAsyncQueryable, IAsyncQueryProvider { private readonly Expression _expression; - private IAsyncEnumerable _enumerable; + private IAsyncEnumerable? _enumerable; /// /// Creates a new asynchronous enumerable sequence represented by the specified expression tree. @@ -72,7 +71,7 @@ public AsyncEnumerableQuery(IAsyncEnumerable enumerable) /// /// Gets the enumerable sequence obtained from evaluating the expression tree. /// - internal override object Enumerable => _enumerable; + internal override object? Enumerable => _enumerable; /// /// Gets the expression tree representing the asynchronous enumerable sequence. diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs index 3185277037..49fd486168 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs @@ -138,7 +138,7 @@ private static Type GetPublicType(Type type) return type; } - private static bool ArgsMatch(MethodInfo method, ReadOnlyCollection args, Type[] typeArgs) + private static bool ArgsMatch(MethodInfo method, ReadOnlyCollection args, Type[]? typeArgs) { // // Number of parameters should match the number of arguments to bind. @@ -388,7 +388,7 @@ private static Type StripExpression(Type type) return elemType.MakeArrayType(); } - private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection args, params Type[] typeArgs) + private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection args, params Type[]? typeArgs) { // // Ensure the cached lookup table for AsyncEnumerable methods is initialized. @@ -418,7 +418,7 @@ private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection args, Type[] typeArgs, BindingFlags flags) + private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection args, Type[]? typeArgs, BindingFlags flags) { // // Support the enumerable methods to be defined on another type. @@ -454,7 +454,7 @@ private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection< return method; } - private static Type FindGenericType(Type definition, Type type) + private static Type? FindGenericType(Type definition, Type type) { while (type != null && type != typeof(object)) { diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs index d8c9ff5f37..bf27da325c 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.cs @@ -956,7 +956,7 @@ private static MethodInfo ContainsAsync__TSource__4__0(Type TSource) => (s_ContainsAsync__TSource__4__0 ?? (s_ContainsAsync__TSource__4__0 = new Func, object, IEqualityComparer, CancellationToken, ValueTask>(ContainsAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static ValueTask ContainsAsync(this IAsyncQueryable source, TSource value, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask ContainsAsync(this IAsyncQueryable source, TSource value, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1074,7 +1074,7 @@ private static MethodInfo Distinct__TSource__2__0(Type TSource) => (s_Distinct__TSource__2__0 ?? (s_Distinct__TSource__2__0 = new Func, IEqualityComparer, IAsyncQueryable>(Distinct).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static IAsyncQueryable Distinct(this IAsyncQueryable source, IEqualityComparer comparer) + public static IAsyncQueryable Distinct(this IAsyncQueryable source, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1132,7 +1132,7 @@ private static MethodInfo Except__TSource__3__0(Type TSource) => (s_Except__TSource__3__0 ?? (s_Except__TSource__3__0 = new Func, IAsyncEnumerable, IEqualityComparer, IAsyncQueryable>(Except).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static IAsyncQueryable Except(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncQueryable Except(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw new ArgumentNullException(nameof(first)); @@ -1288,7 +1288,7 @@ private static MethodInfo GroupBy__TSource_TKey__3__0(Type TSource, Type TKey) = (s_GroupBy__TSource_TKey__3__0 ?? (s_GroupBy__TSource_TKey__3__0 = new Func, Expression>, IEqualityComparer, IAsyncQueryable>>(GroupBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable> GroupBy(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupBy(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1340,7 +1340,7 @@ private static MethodInfo GroupBy__TSource_TKey_TResult__4__0(Type TSource, Type (s_GroupBy__TSource_TKey_TResult__4__0 ?? (s_GroupBy__TSource_TKey_TResult__4__0 = new Func, Expression>, Expression, object>>, IEqualityComparer, IAsyncQueryable>(GroupBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult); - public static IAsyncQueryable GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression, TResult>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression, TResult>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1358,7 +1358,7 @@ private static MethodInfo GroupBy__TSource_TKey_TElement__4__0(Type TSource, Typ (s_GroupBy__TSource_TKey_TElement__4__0 ?? (s_GroupBy__TSource_TKey_TElement__4__0 = new Func, Expression>, Expression>, IEqualityComparer, IAsyncQueryable>>(GroupBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static IAsyncQueryable> GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1396,7 +1396,7 @@ private static MethodInfo GroupBy__TSource_TKey_TElement_TResult__5__0(Type TSou (s_GroupBy__TSource_TKey_TElement_TResult__5__0 ?? (s_GroupBy__TSource_TKey_TElement_TResult__5__0 = new Func, Expression>, Expression>, Expression, object>>, IEqualityComparer, IAsyncQueryable>(GroupBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult); - public static IAsyncQueryable GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, Expression, TResult>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupBy(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, Expression, TResult>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1432,7 +1432,7 @@ private static MethodInfo GroupByAwait__TSource_TKey__3__0(Type TSource, Type TK (s_GroupByAwait__TSource_TKey__3__0 ?? (s_GroupByAwait__TSource_TKey__3__0 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>>(GroupByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable> GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1484,7 +1484,7 @@ private static MethodInfo GroupByAwait__TSource_TKey_TResult__4__0(Type TSource, (s_GroupByAwait__TSource_TKey_TResult__4__0 ?? (s_GroupByAwait__TSource_TKey_TResult__4__0 = new Func, Expression>>, Expression, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult); - public static IAsyncQueryable GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1502,7 +1502,7 @@ private static MethodInfo GroupByAwait__TSource_TKey_TElement__4__0(Type TSource (s_GroupByAwait__TSource_TKey_TElement__4__0 ?? (s_GroupByAwait__TSource_TKey_TElement__4__0 = new Func, Expression>>, Expression>>, IEqualityComparer, IAsyncQueryable>>(GroupByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static IAsyncQueryable> GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1540,7 +1540,7 @@ private static MethodInfo GroupByAwait__TSource_TKey_TElement_TResult__5__0(Type (s_GroupByAwait__TSource_TKey_TElement_TResult__5__0 ?? (s_GroupByAwait__TSource_TKey_TElement_TResult__5__0 = new Func, Expression>>, Expression>>, Expression, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult); - public static IAsyncQueryable GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, Expression, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupByAwait(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, Expression, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1576,7 +1576,7 @@ private static MethodInfo GroupByAwaitWithCancellation__TSource_TKey__3__0(Type (s_GroupByAwaitWithCancellation__TSource_TKey__3__0 ?? (s_GroupByAwaitWithCancellation__TSource_TKey__3__0 = new Func, Expression>>, IEqualityComparer, IAsyncQueryable>>(GroupByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IAsyncQueryable> GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1628,7 +1628,7 @@ private static MethodInfo GroupByAwaitWithCancellation__TSource_TKey_TResult__4_ (s_GroupByAwaitWithCancellation__TSource_TKey_TResult__4__0 ?? (s_GroupByAwaitWithCancellation__TSource_TKey_TResult__4__0 = new Func, Expression>>, Expression, CancellationToken, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TResult); - public static IAsyncQueryable GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1646,7 +1646,7 @@ private static MethodInfo GroupByAwaitWithCancellation__TSource_TKey_TElement__4 (s_GroupByAwaitWithCancellation__TSource_TKey_TElement__4__0 ?? (s_GroupByAwaitWithCancellation__TSource_TKey_TElement__4__0 = new Func, Expression>>, Expression>>, IEqualityComparer, IAsyncQueryable>>(GroupByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static IAsyncQueryable> GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer) + public static IAsyncQueryable> GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1684,7 +1684,7 @@ private static MethodInfo GroupByAwaitWithCancellation__TSource_TKey_TElement_TR (s_GroupByAwaitWithCancellation__TSource_TKey_TElement_TResult__5__0 ?? (s_GroupByAwaitWithCancellation__TSource_TKey_TElement_TResult__5__0 = new Func, Expression>>, Expression>>, Expression, CancellationToken, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement, TResult); - public static IAsyncQueryable GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -1726,7 +1726,7 @@ private static MethodInfo GroupJoin__TOuter_TInner_TKey_TResult__6__0(Type TOute (s_GroupJoin__TOuter_TInner_TKey_TResult__6__0 ?? (s_GroupJoin__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>, Expression>, Expression, object>>, IEqualityComparer, IAsyncQueryable>(GroupJoin).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable GroupJoin(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupJoin(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression, TResult>> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -1770,7 +1770,7 @@ private static MethodInfo GroupJoinAwait__TOuter_TInner_TKey_TResult__6__0(Type (s_GroupJoinAwait__TOuter_TInner_TKey_TResult__6__0 ?? (s_GroupJoinAwait__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>>, Expression>>, Expression, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupJoinAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable GroupJoinAwait(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupJoinAwait(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -1814,7 +1814,7 @@ private static MethodInfo GroupJoinAwaitWithCancellation__TOuter_TInner_TKey_TRe (s_GroupJoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 ?? (s_GroupJoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>>, Expression>>, Expression, CancellationToken, ValueTask>>, IEqualityComparer, IAsyncQueryable>(GroupJoinAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable GroupJoinAwaitWithCancellation(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable GroupJoinAwaitWithCancellation(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression, CancellationToken, ValueTask>> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -1852,7 +1852,7 @@ private static MethodInfo Intersect__TSource__3__0(Type TSource) => (s_Intersect__TSource__3__0 ?? (s_Intersect__TSource__3__0 = new Func, IAsyncEnumerable, IEqualityComparer, IAsyncQueryable>(Intersect).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static IAsyncQueryable Intersect(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncQueryable Intersect(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw new ArgumentNullException(nameof(first)); @@ -1890,7 +1890,7 @@ private static MethodInfo Join__TOuter_TInner_TKey_TResult__6__0(Type TOuter, Ty (s_Join__TOuter_TInner_TKey_TResult__6__0 ?? (s_Join__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>, Expression>, Expression>, IEqualityComparer, IAsyncQueryable>(Join).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable Join(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable Join(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression> outerKeySelector, Expression> innerKeySelector, Expression> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -1934,7 +1934,7 @@ private static MethodInfo JoinAwait__TOuter_TInner_TKey_TResult__6__0(Type TOute (s_JoinAwait__TOuter_TInner_TKey_TResult__6__0 ?? (s_JoinAwait__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>>, Expression>>, Expression>>, IEqualityComparer, IAsyncQueryable>(JoinAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable JoinAwait(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable JoinAwait(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression>> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -1978,7 +1978,7 @@ private static MethodInfo JoinAwaitWithCancellation__TOuter_TInner_TKey_TResult_ (s_JoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 ?? (s_JoinAwaitWithCancellation__TOuter_TInner_TKey_TResult__6__0 = new Func, IAsyncEnumerable, Expression>>, Expression>>, Expression>>, IEqualityComparer, IAsyncQueryable>(JoinAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TOuter, TInner, TKey, TResult); - public static IAsyncQueryable JoinAwaitWithCancellation(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression>> resultSelector, IEqualityComparer comparer) + public static IAsyncQueryable JoinAwaitWithCancellation(this IAsyncQueryable outer, IAsyncEnumerable inner, Expression>> outerKeySelector, Expression>> innerKeySelector, Expression>> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw new ArgumentNullException(nameof(outer)); @@ -3580,7 +3580,7 @@ private static MethodInfo OrderBy__TSource_TKey__3__0(Type TSource, Type TKey) = (s_OrderBy__TSource_TKey__3__0 ?? (s_OrderBy__TSource_TKey__3__0 = new Func, Expression>, IComparer, IOrderedAsyncQueryable>(OrderBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderBy(this IAsyncQueryable source, Expression> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderBy(this IAsyncQueryable source, Expression> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -3612,7 +3612,7 @@ private static MethodInfo OrderByAwait__TSource_TKey__3__0(Type TSource, Type TK (s_OrderByAwait__TSource_TKey__3__0 ?? (s_OrderByAwait__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(OrderByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderByAwait(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderByAwait(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -3644,7 +3644,7 @@ private static MethodInfo OrderByAwaitWithCancellation__TSource_TKey__3__0(Type (s_OrderByAwaitWithCancellation__TSource_TKey__3__0 ?? (s_OrderByAwaitWithCancellation__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(OrderByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderByAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -3676,7 +3676,7 @@ private static MethodInfo OrderByDescending__TSource_TKey__3__0(Type TSource, Ty (s_OrderByDescending__TSource_TKey__3__0 ?? (s_OrderByDescending__TSource_TKey__3__0 = new Func, Expression>, IComparer, IOrderedAsyncQueryable>(OrderByDescending).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderByDescending(this IAsyncQueryable source, Expression> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderByDescending(this IAsyncQueryable source, Expression> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -3708,7 +3708,7 @@ private static MethodInfo OrderByDescendingAwait__TSource_TKey__3__0(Type TSourc (s_OrderByDescendingAwait__TSource_TKey__3__0 ?? (s_OrderByDescendingAwait__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(OrderByDescendingAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderByDescendingAwait(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderByDescendingAwait(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -3740,7 +3740,7 @@ private static MethodInfo OrderByDescendingAwaitWithCancellation__TSource_TKey__ (s_OrderByDescendingAwaitWithCancellation__TSource_TKey__3__0 ?? (s_OrderByDescendingAwaitWithCancellation__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(OrderByDescendingAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable OrderByDescendingAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable OrderByDescendingAwaitWithCancellation(this IAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -4100,7 +4100,7 @@ private static MethodInfo SequenceEqualAsync__TSource__4__0(Type TSource) => (s_SequenceEqualAsync__TSource__4__0 ?? (s_SequenceEqualAsync__TSource__4__0 = new Func, IAsyncEnumerable, IEqualityComparer, CancellationToken, ValueTask>(SequenceEqualAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static ValueTask SequenceEqualAsync(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask SequenceEqualAsync(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (first == null) throw new ArgumentNullException(nameof(first)); @@ -5124,7 +5124,7 @@ private static MethodInfo ThenBy__TSource_TKey__3__0(Type TSource, Type TKey) => (s_ThenBy__TSource_TKey__3__0 ?? (s_ThenBy__TSource_TKey__3__0 = new Func, Expression>, IComparer, IOrderedAsyncQueryable>(ThenBy).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenBy(this IOrderedAsyncQueryable source, Expression> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenBy(this IOrderedAsyncQueryable source, Expression> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5156,7 +5156,7 @@ private static MethodInfo ThenByAwait__TSource_TKey__3__0(Type TSource, Type TKe (s_ThenByAwait__TSource_TKey__3__0 ?? (s_ThenByAwait__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(ThenByAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenByAwait(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenByAwait(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5188,7 +5188,7 @@ private static MethodInfo ThenByAwaitWithCancellation__TSource_TKey__3__0(Type T (s_ThenByAwaitWithCancellation__TSource_TKey__3__0 ?? (s_ThenByAwaitWithCancellation__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(ThenByAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenByAwaitWithCancellation(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenByAwaitWithCancellation(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5220,7 +5220,7 @@ private static MethodInfo ThenByDescending__TSource_TKey__3__0(Type TSource, Typ (s_ThenByDescending__TSource_TKey__3__0 ?? (s_ThenByDescending__TSource_TKey__3__0 = new Func, Expression>, IComparer, IOrderedAsyncQueryable>(ThenByDescending).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenByDescending(this IOrderedAsyncQueryable source, Expression> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenByDescending(this IOrderedAsyncQueryable source, Expression> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5252,7 +5252,7 @@ private static MethodInfo ThenByDescendingAwait__TSource_TKey__3__0(Type TSource (s_ThenByDescendingAwait__TSource_TKey__3__0 ?? (s_ThenByDescendingAwait__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(ThenByDescendingAwait).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenByDescendingAwait(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenByDescendingAwait(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5284,7 +5284,7 @@ private static MethodInfo ThenByDescendingAwaitWithCancellation__TSource_TKey__3 (s_ThenByDescendingAwaitWithCancellation__TSource_TKey__3__0 ?? (s_ThenByDescendingAwaitWithCancellation__TSource_TKey__3__0 = new Func, Expression>>, IComparer, IOrderedAsyncQueryable>(ThenByDescendingAwaitWithCancellation).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static IOrderedAsyncQueryable ThenByDescendingAwaitWithCancellation(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer comparer) + public static IOrderedAsyncQueryable ThenByDescendingAwaitWithCancellation(this IOrderedAsyncQueryable source, Expression>> keySelector, IComparer? comparer) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5330,7 +5330,7 @@ private static MethodInfo ToDictionaryAsync__TSource_TKey__4__0(Type TSource, Ty (s_ToDictionaryAsync__TSource_TKey__4__0 ?? (s_ToDictionaryAsync__TSource_TKey__4__0 = new Func, Expression>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToDictionaryAsync(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAsync(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5364,7 +5364,7 @@ private static MethodInfo ToDictionaryAsync__TSource_TKey_TElement__5__0(Type TS (s_ToDictionaryAsync__TSource_TKey_TElement__5__0 ?? (s_ToDictionaryAsync__TSource_TKey_TElement__5__0 = new Func, Expression>, Expression>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToDictionaryAsync(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAsync(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5398,7 +5398,7 @@ private static MethodInfo ToDictionaryAwaitAsync__TSource_TKey__4__0(Type TSourc (s_ToDictionaryAwaitAsync__TSource_TKey__4__0 ?? (s_ToDictionaryAwaitAsync__TSource_TKey__4__0 = new Func, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAwaitAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToDictionaryAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5432,7 +5432,7 @@ private static MethodInfo ToDictionaryAwaitAsync__TSource_TKey_TElement__5__0(Ty (s_ToDictionaryAwaitAsync__TSource_TKey_TElement__5__0 ?? (s_ToDictionaryAwaitAsync__TSource_TKey_TElement__5__0 = new Func, Expression>>, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAwaitAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToDictionaryAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5466,7 +5466,7 @@ private static MethodInfo ToDictionaryAwaitWithCancellationAsync__TSource_TKey__ (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey__4__0 ?? (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey__4__0 = new Func, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAwaitWithCancellationAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5500,7 +5500,7 @@ private static MethodInfo ToDictionaryAwaitWithCancellationAsync__TSource_TKey_T (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 ?? (s_ToDictionaryAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 = new Func, Expression>>, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToDictionaryAwaitWithCancellationAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5532,7 +5532,7 @@ private static MethodInfo ToHashSetAsync__TSource__3__0(Type TSource) => (s_ToHashSetAsync__TSource__3__0 ?? (s_ToHashSetAsync__TSource__3__0 = new Func, IEqualityComparer, CancellationToken, ValueTask>>(ToHashSetAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static ValueTask> ToHashSetAsync(this IAsyncQueryable source, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToHashSetAsync(this IAsyncQueryable source, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5576,7 +5576,7 @@ private static MethodInfo ToLookupAsync__TSource_TKey__4__0(Type TSource, Type T (s_ToLookupAsync__TSource_TKey__4__0 ?? (s_ToLookupAsync__TSource_TKey__4__0 = new Func, Expression>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToLookupAsync(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAsync(this IAsyncQueryable source, Expression> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5610,7 +5610,7 @@ private static MethodInfo ToLookupAsync__TSource_TKey_TElement__5__0(Type TSourc (s_ToLookupAsync__TSource_TKey_TElement__5__0 ?? (s_ToLookupAsync__TSource_TKey_TElement__5__0 = new Func, Expression>, Expression>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToLookupAsync(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAsync(this IAsyncQueryable source, Expression> keySelector, Expression> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5644,7 +5644,7 @@ private static MethodInfo ToLookupAwaitAsync__TSource_TKey__4__0(Type TSource, T (s_ToLookupAwaitAsync__TSource_TKey__4__0 ?? (s_ToLookupAwaitAsync__TSource_TKey__4__0 = new Func, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAwaitAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToLookupAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5678,7 +5678,7 @@ private static MethodInfo ToLookupAwaitAsync__TSource_TKey_TElement__5__0(Type T (s_ToLookupAwaitAsync__TSource_TKey_TElement__5__0 ?? (s_ToLookupAwaitAsync__TSource_TKey_TElement__5__0 = new Func, Expression>>, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAwaitAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToLookupAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAwaitAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5712,7 +5712,7 @@ private static MethodInfo ToLookupAwaitWithCancellationAsync__TSource_TKey__4__0 (s_ToLookupAwaitWithCancellationAsync__TSource_TKey__4__0 ?? (s_ToLookupAwaitWithCancellationAsync__TSource_TKey__4__0 = new Func, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAwaitWithCancellationAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey); - public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5746,7 +5746,7 @@ private static MethodInfo ToLookupAwaitWithCancellationAsync__TSource_TKey_TElem (s_ToLookupAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 ?? (s_ToLookupAwaitWithCancellationAsync__TSource_TKey_TElement__5__0 = new Func, Expression>>, Expression>>, IEqualityComparer, CancellationToken, ValueTask>>(ToLookupAwaitWithCancellationAsync).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource, TKey, TElement); - public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncQueryable source, Expression>> keySelector, Expression>> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw new ArgumentNullException(nameof(source)); @@ -5780,7 +5780,7 @@ private static MethodInfo Union__TSource__3__0(Type TSource) => (s_Union__TSource__3__0 ?? (s_Union__TSource__3__0 = new Func, IAsyncEnumerable, IEqualityComparer, IAsyncQueryable>(Union).GetMethodInfo().GetGenericMethodDefinition())).MakeGenericMethod(TSource); - public static IAsyncQueryable Union(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncQueryable Union(this IAsyncQueryable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw new ArgumentNullException(nameof(first)); diff --git a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt index 82b1907f5d..75db384663 100644 --- a/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt +++ b/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncQueryable.Generated.tt @@ -3,8 +3,9 @@ // See the LICENSE file in the project root for more information. <#@ template debug="false" hostspecific="false" language="C#" #> -<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Threading.Tasks.Extensions.dll" #> -<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net46\System.Linq.Async.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\Microsoft.Bcl.AsyncInterfaces.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Threading.Tasks.Extensions.dll" #> +<#@ assembly name="$(ProjectDir)\..\System.Linq.Async\bin\$(Configuration)\net461\System.Linq.Async.dll" #> <#@ output extension=".cs" #> <# var asyncEnumerableType = typeof(AsyncEnumerable); diff --git a/Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj b/Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj index d3cf17191b..d05afd40b6 100644 --- a/Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj +++ b/Ix.NET/Source/System.Linq.Async/System.Linq.Async.csproj @@ -2,6 +2,7 @@ net461;netstandard2.0;netstandard2.1;netcoreapp3.0 + enable diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs index d3ad271a03..c1a2679d3a 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerableHelpers.cs @@ -102,7 +102,7 @@ internal static async ValueTask> ToArrayWithLength(IAsyncE return result; } - internal static async Task> ToSet(IAsyncEnumerable source, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> ToSet(IAsyncEnumerable source, IEqualityComparer? comparer, CancellationToken cancellationToken) { var set = new Set(comparer); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs index 7f27b08c5f..f6f712422f 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerablePartition.cs @@ -21,7 +21,7 @@ internal sealed class AsyncEnumerablePartition : AsyncIterator private readonly int _minIndexInclusive; private readonly int _maxIndexInclusive; // -1 if we want everything past _minIndexInclusive. // If this is -1, it's impossible to set a limit on the count. - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; internal AsyncEnumerablePartition(IAsyncEnumerable source, int minIndexInclusive, int maxIndexInclusive) { @@ -122,7 +122,7 @@ protected override async ValueTask MoveNextCore() case AsyncIteratorState.Iterating: if (!_hasSkipped) { - if (!await SkipBeforeFirstAsync(_enumerator).ConfigureAwait(false)) + if (!await SkipBeforeFirstAsync(_enumerator!).ConfigureAwait(false)) { // Reached the end before we finished skipping. break; @@ -131,7 +131,7 @@ protected override async ValueTask MoveNextCore() _hasSkipped = true; } - if ((!HasLimit || _taken < Limit) && await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if ((!HasLimit || _taken < Limit) && await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { if (HasLimit) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs index fd389f549c..42811a7dd0 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerator.cs @@ -63,7 +63,7 @@ private sealed class AnonymousAsyncIterator : AsyncIterator { private readonly Func _currentFunc; private readonly Func> _moveNext; - private Func _dispose; + private Func? _dispose; public AnonymousAsyncIterator(Func> moveNext, Func currentFunc, Func dispose) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs index 21720b8a70..4fd6f955c1 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/AsyncIterator.cs @@ -83,13 +83,13 @@ public async ValueTask MoveNextAsync() internal abstract class AsyncIterator : AsyncIteratorBase { - protected TSource _current; + protected TSource _current = default!; public override TSource Current => _current; public override ValueTask DisposeAsync() { - _current = default; + _current = default!; return base.DisposeAsync(); } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs index d5fee14f94..74d394ca78 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Disposables.cs @@ -30,8 +30,8 @@ internal static class Disposable internal sealed class BinaryDisposable : IDisposable { - private IDisposable _d1; - private IDisposable _d2; + private IDisposable? _d1; + private IDisposable? _d2; public BinaryDisposable(IDisposable d1, IDisposable d2) { @@ -57,7 +57,7 @@ public void Dispose() internal sealed class AnonymousDisposable : IDisposable { - private Action _action; + private Action? _action; public AnonymousDisposable(Action action) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs index 26d0b1ab7e..e064a118ba 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/IOrderedAsyncEnumerable.cs @@ -10,11 +10,11 @@ namespace System.Linq { public interface IOrderedAsyncEnumerable : IAsyncEnumerable { - IOrderedAsyncEnumerable CreateOrderedEnumerable(Func keySelector, IComparer comparer, bool descending); - IOrderedAsyncEnumerable CreateOrderedEnumerable(Func> keySelector, IComparer comparer, bool descending); + IOrderedAsyncEnumerable CreateOrderedEnumerable(Func keySelector, IComparer? comparer, bool descending); + IOrderedAsyncEnumerable CreateOrderedEnumerable(Func> keySelector, IComparer? comparer, bool descending); #if !NO_DEEP_CANCELLATION - IOrderedAsyncEnumerable CreateOrderedEnumerable(Func> keySelector, IComparer comparer, bool descending); + IOrderedAsyncEnumerable CreateOrderedEnumerable(Func> keySelector, IComparer? comparer, bool descending); #endif } } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs index a1191c7aab..a94c218d61 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/AppendPrepend.cs @@ -41,7 +41,7 @@ public static IAsyncEnumerable Prepend(this IAsyncEnumerable : AsyncIterator, IAsyncIListProvider { protected readonly IAsyncEnumerable _source; - protected IAsyncEnumerator _enumerator; + protected IAsyncEnumerator? _enumerator; protected AppendPrependAsyncIterator(IAsyncEnumerable source) { @@ -61,7 +61,7 @@ protected void GetSourceEnumerator(CancellationToken cancellationToken) protected async Task LoadFromEnumeratorAsync() { - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -261,15 +261,15 @@ public override async ValueTask GetCountAsync(bool onlyIfCheap, Cancellatio private sealed class AppendPrependNAsyncIterator : AppendPrependAsyncIterator { - private readonly SingleLinkedNode _prepended; - private readonly SingleLinkedNode _appended; + private readonly SingleLinkedNode? _prepended; + private readonly SingleLinkedNode? _appended; private readonly int _prependCount; private readonly int _appendCount; - private SingleLinkedNode _node; + private SingleLinkedNode? _node; private int _mode; - private IEnumerator _appendedEnumerator; + private IEnumerator? _appendedEnumerator; - public AppendPrependNAsyncIterator(IAsyncEnumerable source, SingleLinkedNode prepended, SingleLinkedNode appended, int prependCount, int appendCount) + public AppendPrependNAsyncIterator(IAsyncEnumerable source, SingleLinkedNode? prepended, SingleLinkedNode? appended, int prependCount, int appendCount) : base(source) { Debug.Assert(prepended != null || appended != null); @@ -346,7 +346,7 @@ protected override async ValueTask MoveNextCore() case 4: - if (_appendedEnumerator.MoveNext()) + if (_appendedEnumerator!.MoveNext()) { _current = _appendedEnumerator.Current; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs index 25ca35bfe2..97cb955fd4 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Concat.cs @@ -47,7 +47,7 @@ internal override ConcatAsyncIterator Concat(IAsyncEnumerable return new ConcatNAsyncIterator(this, next, 2); } - internal override IAsyncEnumerable GetAsyncEnumerable(int index) + internal override IAsyncEnumerable? GetAsyncEnumerable(int index) { switch (index) { @@ -64,7 +64,7 @@ internal override IAsyncEnumerable GetAsyncEnumerable(int index) private abstract class ConcatAsyncIterator : AsyncIterator, IAsyncIListProvider { private int _counter; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public ValueTask ToArrayAsync(CancellationToken cancellationToken) { @@ -140,7 +140,7 @@ protected override async ValueTask MoveNextCore() { if (_state == AsyncIteratorState.Allocated) { - _enumerator = GetAsyncEnumerable(0).GetAsyncEnumerator(_cancellationToken); + _enumerator = GetAsyncEnumerable(0)!.GetAsyncEnumerator(_cancellationToken); _state = AsyncIteratorState.Iterating; _counter = 2; } @@ -149,7 +149,7 @@ protected override async ValueTask MoveNextCore() { while (true) { - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -178,7 +178,7 @@ protected override async ValueTask MoveNextCore() internal abstract ConcatAsyncIterator Concat(IAsyncEnumerable next); - internal abstract IAsyncEnumerable GetAsyncEnumerable(int index); + internal abstract IAsyncEnumerable? GetAsyncEnumerable(int index); } // To handle chains of >= 3 sources, we chain the concat iterators together and allow @@ -222,7 +222,7 @@ internal override ConcatAsyncIterator Concat(IAsyncEnumerable return new ConcatNAsyncIterator(this, next, _nextIndex + 1); } - internal override IAsyncEnumerable GetAsyncEnumerable(int index) + internal override IAsyncEnumerable? GetAsyncEnumerable(int index) { if (index > _nextIndex) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs index 1d5ffca617..b30025a8f8 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Contains.cs @@ -14,7 +14,7 @@ public static ValueTask ContainsAsync(this IAsyncEnumerable collection ? new ValueTask(collection.Contains(value)) : ContainsAsync(source, value, comparer: null, cancellationToken); - public static ValueTask ContainsAsync(this IAsyncEnumerable source, TSource value, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask ContainsAsync(this IAsyncEnumerable source, TSource value, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs index 090bde8543..663aa816a1 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/DefaultIfEmpty.cs @@ -13,7 +13,7 @@ namespace System.Linq public static partial class AsyncEnumerable { public static IAsyncEnumerable DefaultIfEmpty(this IAsyncEnumerable source) => - DefaultIfEmpty(source, default); + DefaultIfEmpty(source, default!); public static IAsyncEnumerable DefaultIfEmpty(this IAsyncEnumerable source, TSource defaultValue) { @@ -28,7 +28,7 @@ private sealed class DefaultIfEmptyAsyncIterator : AsyncIterator _source; private readonly TSource _defaultValue; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public DefaultIfEmptyAsyncIterator(IAsyncEnumerable source, TSource defaultValue) { @@ -76,7 +76,7 @@ protected override async ValueTask MoveNextCore() return true; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs index e98179a813..ea2bbf4b3d 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Distinct.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable { public static IAsyncEnumerable Distinct(this IAsyncEnumerable source) => Distinct(source, comparer: null); - public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, IEqualityComparer comparer) + public static IAsyncEnumerable Distinct(this IAsyncEnumerable source, IEqualityComparer? comparer) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -23,13 +23,13 @@ public static IAsyncEnumerable Distinct(this IAsyncEnumerable< private sealed class DistinctAsyncIterator : AsyncIterator, IAsyncIListProvider { - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; - private Set _set; + private IAsyncEnumerator? _enumerator; + private Set? _set; - public DistinctAsyncIterator(IAsyncEnumerable source, IEqualityComparer comparer) + public DistinctAsyncIterator(IAsyncEnumerable source, IEqualityComparer? comparer) { Debug.Assert(source != null); @@ -103,10 +103,10 @@ protected override async ValueTask MoveNextCore() return true; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { element = _enumerator.Current; - if (_set.Add(element)) + if (_set!.Add(element)) { _current = element; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs index 1fa20fb3d6..1c85edb3d0 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs @@ -52,7 +52,7 @@ static async ValueTask Core(IAsyncEnumerable source, int index } } - return default; + return default!; } } } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs index 1ceb249ee8..e0727f69c2 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs @@ -16,7 +16,7 @@ internal sealed class EmptyAsyncIterator : IAsyncPartition, IAsy { public static readonly EmptyAsyncIterator Instance = new EmptyAsyncIterator(); - public TValue Current => default; + public TValue Current => default!; public ValueTask GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken) => new ValueTask(0); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs index 934280e9ec..4b5492dd7b 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Except.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable public static IAsyncEnumerable Except(this IAsyncEnumerable first, IAsyncEnumerable second) => Except(first, second, comparer: null); - public static IAsyncEnumerable Except(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncEnumerable Except(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw Error.ArgumentNull(nameof(first)); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs index 0ffd62322e..d15acdb427 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs @@ -21,7 +21,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { var first = await TryGetFirst(source, cancellationToken).ConfigureAwait(false); - return first.HasValue ? first.Value : default; + return first.HasValue ? first.Value : default!; } } @@ -38,7 +38,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func> GroupBy(this IAsyncEnumerable source, Func keySelector) => new GroupedAsyncEnumerable(source, keySelector, comparer: null); - public static IAsyncEnumerable> GroupBy(this IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) => + public static IAsyncEnumerable> GroupBy(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerable(source, keySelector, comparer); internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector) => new GroupedAsyncEnumerableWithTask(source, keySelector, comparer: null); - internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerableWithTask(source, keySelector, comparer); #if !NO_DEEP_CANCELLATION internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector) => new GroupedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer: null); - internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerableWithTaskAndCancellation(source, keySelector, comparer); #endif public static IAsyncEnumerable> GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector) => new GroupedAsyncEnumerable(source, keySelector, elementSelector, comparer: null); - public static IAsyncEnumerable> GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer) => + public static IAsyncEnumerable> GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerable(source, keySelector, elementSelector, comparer); internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector) => new GroupedAsyncEnumerableWithTask(source, keySelector, elementSelector, comparer: null); - internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable> GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerableWithTask(source, keySelector, elementSelector, comparer); #if !NO_DEEP_CANCELLATION internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector) => new GroupedAsyncEnumerableWithTaskAndCancellation(source, keySelector, elementSelector, comparer: null); - internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable> GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer) => new GroupedAsyncEnumerableWithTaskAndCancellation(source, keySelector, elementSelector, comparer); #endif public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func, TResult> resultSelector) => new GroupedResultAsyncEnumerable(source, keySelector, resultSelector, comparer: null); - public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func, TResult> resultSelector, IEqualityComparer comparer) => + public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func, TResult> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerable(source, keySelector, resultSelector, comparer); internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func, ValueTask> resultSelector) => new GroupedResultAsyncEnumerableWithTask(source, keySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func, ValueTask> resultSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func, ValueTask> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerableWithTask(source, keySelector, resultSelector, comparer); #if !NO_DEEP_CANCELLATION internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func, CancellationToken, ValueTask> resultSelector) => new GroupedResultAsyncEnumerableWithTaskAndCancellation(source, keySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerableWithTaskAndCancellation(source, keySelector, resultSelector, comparer); #endif public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector) => new GroupedResultAsyncEnumerable(source, keySelector, elementSelector, resultSelector, comparer: null); - public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer) => + public static IAsyncEnumerable GroupBy(this IAsyncEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerable(source, keySelector, elementSelector, resultSelector, comparer); internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, ValueTask> resultSelector) => new GroupedResultAsyncEnumerableWithTask(source, keySelector, elementSelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, ValueTask> resultSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable GroupByAwaitCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, ValueTask> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerableWithTask(source, keySelector, elementSelector, resultSelector, comparer); #if !NO_DEEP_CANCELLATION internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, CancellationToken, ValueTask> resultSelector) => new GroupedResultAsyncEnumerableWithTaskAndCancellation(source, keySelector, elementSelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer comparer) => + internal static IAsyncEnumerable GroupByAwaitWithCancellationCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer? comparer) => new GroupedResultAsyncEnumerableWithTaskAndCancellation(source, keySelector, elementSelector, resultSelector, comparer); #endif @@ -95,12 +95,12 @@ private sealed class GroupedResultAsyncEnumerable : Asyn private readonly IAsyncEnumerable _source; private readonly Func _keySelector; private readonly Func, TResult> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.Lookup _lookup; - private IEnumerator _enumerator; + private Internal.Lookup? _lookup; + private IEnumerator? _enumerator; - public GroupedResultAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func, TResult> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func, TResult> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -136,7 +136,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _enumerator.Current; return true; @@ -184,12 +184,12 @@ private sealed class GroupedResultAsyncEnumerableWithTask _source; private readonly Func> _keySelector; private readonly Func, ValueTask> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IAsyncEnumerator _enumerator; + private Internal.LookupWithTask? _lookup; + private IAsyncEnumerator? _enumerator; - public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func, ValueTask> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func, ValueTask> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -225,7 +225,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -274,12 +274,12 @@ private sealed class GroupedResultAsyncEnumerableWithTaskAndCancellation _source; private readonly Func> _keySelector; private readonly Func, CancellationToken, ValueTask> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IAsyncEnumerator _enumerator; + private Internal.LookupWithTask? _lookup; + private IAsyncEnumerator? _enumerator; - public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -315,7 +315,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -365,12 +365,12 @@ private sealed class GroupedResultAsyncEnumerable _keySelector; private readonly Func _elementSelector; private readonly Func, TResult> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.Lookup _lookup; - private IEnumerator _enumerator; + private Internal.Lookup? _lookup; + private IEnumerator? _enumerator; - public GroupedResultAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -407,7 +407,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _enumerator.Current; return true; @@ -456,12 +456,12 @@ private sealed class GroupedResultAsyncEnumerableWithTask> _keySelector; private readonly Func> _elementSelector; private readonly Func, ValueTask> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IAsyncEnumerator _enumerator; + private Internal.LookupWithTask? _lookup; + private IAsyncEnumerator? _enumerator; - public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, ValueTask> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, ValueTask> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -498,7 +498,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -548,12 +548,12 @@ private sealed class GroupedResultAsyncEnumerableWithTaskAndCancellation> _keySelector; private readonly Func> _elementSelector; private readonly Func, CancellationToken, ValueTask> _resultSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IAsyncEnumerator _enumerator; + private Internal.LookupWithTask? _lookup; + private IAsyncEnumerator? _enumerator; - public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer comparer) + public GroupedResultAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -590,7 +590,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _enumerator.Current; return true; @@ -639,12 +639,12 @@ private sealed class GroupedAsyncEnumerable : AsyncIter private readonly IAsyncEnumerable _source; private readonly Func _keySelector; private readonly Func _elementSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.Lookup _lookup; - private IEnumerator> _enumerator; + private Internal.Lookup? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer) + public GroupedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -680,7 +680,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; @@ -728,12 +728,12 @@ private sealed class GroupedAsyncEnumerableWithTask : A private readonly IAsyncEnumerable _source; private readonly Func> _keySelector; private readonly Func> _elementSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IEnumerator> _enumerator; + private Internal.LookupWithTask? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer) + public GroupedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -769,7 +769,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; @@ -818,12 +818,12 @@ private sealed class GroupedAsyncEnumerableWithTaskAndCancellation _source; private readonly Func> _keySelector; private readonly Func> _elementSelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IEnumerator> _enumerator; + private Internal.LookupWithTask? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer) + public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -859,7 +859,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; @@ -907,12 +907,12 @@ private sealed class GroupedAsyncEnumerable : AsyncIterator _source; private readonly Func _keySelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.Lookup _lookup; - private IEnumerator> _enumerator; + private Internal.Lookup? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer) + public GroupedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -947,7 +947,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; @@ -994,12 +994,12 @@ private sealed class GroupedAsyncEnumerableWithTask : AsyncIterat { private readonly IAsyncEnumerable _source; private readonly Func> _keySelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IEnumerator> _enumerator; + private Internal.LookupWithTask? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public GroupedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -1034,7 +1034,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; @@ -1082,12 +1082,12 @@ private sealed class GroupedAsyncEnumerableWithTaskAndCancellation _source; private readonly Func> _keySelector; - private readonly IEqualityComparer _comparer; + private readonly IEqualityComparer? _comparer; - private Internal.LookupWithTask _lookup; - private IEnumerator> _enumerator; + private Internal.LookupWithTask? _lookup; + private IEnumerator>? _enumerator; - public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer) + public GroupedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer) { _source = source ?? throw Error.ArgumentNull(nameof(source)); _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -1122,7 +1122,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = (IAsyncGrouping)_enumerator.Current; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs index 05be11a3a6..422fe540a3 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/GroupJoin.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable public static IAsyncEnumerable GroupJoin(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func, TResult> resultSelector) => GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - public static IAsyncEnumerable GroupJoin(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func, TResult> resultSelector, IEqualityComparer comparer) + public static IAsyncEnumerable GroupJoin(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func, TResult> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); @@ -51,7 +51,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) internal static IAsyncEnumerable GroupJoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, ValueTask> resultSelector) => GroupJoinAwaitCore(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupJoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, ValueTask> resultSelector, IEqualityComparer comparer) + internal static IAsyncEnumerable GroupJoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, ValueTask> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); @@ -90,7 +90,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) internal static IAsyncEnumerable GroupJoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, CancellationToken, ValueTask> resultSelector) => GroupJoinAwaitWithCancellationCore(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable GroupJoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer comparer) + internal static IAsyncEnumerable GroupJoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func, CancellationToken, ValueTask> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs index 4ba525187f..8787b0cc01 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Grouping.cs @@ -19,7 +19,15 @@ internal class Grouping : IGrouping, IList _hashNext; internal TKey _key; - internal Grouping _next; + internal Grouping? _next; + + public Grouping(TKey key, int hashCode, TElement[] elements, Grouping hashNext) + { + _key = key; + _hashCode = hashCode; + _elements = elements; + _hashNext = hashNext; + } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs index 4606644f4d..5359bc7625 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Intersect.cs @@ -14,7 +14,7 @@ public static partial class AsyncEnumerable public static IAsyncEnumerable Intersect(this IAsyncEnumerable first, IAsyncEnumerable second) => Intersect(first, second, comparer: null); - public static IAsyncEnumerable Intersect(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncEnumerable Intersect(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw Error.ArgumentNull(nameof(first)); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs index f1a5b6d568..c184a50409 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Join.cs @@ -14,7 +14,7 @@ public static partial class AsyncEnumerable public static IAsyncEnumerable Join(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) => Join(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - public static IAsyncEnumerable Join(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector, IEqualityComparer comparer) + public static IAsyncEnumerable Join(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); @@ -45,7 +45,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var outerKey = outerKeySelector(item); - var g = lookup.GetGrouping(outerKey, create: false); + var g = lookup.GetGrouping(outerKey); if (g != null) { @@ -68,7 +68,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) internal static IAsyncEnumerable JoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector) => JoinAwaitCore(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable JoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector, IEqualityComparer comparer) + internal static IAsyncEnumerable JoinAwaitCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); @@ -99,7 +99,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var outerKey = await outerKeySelector(item).ConfigureAwait(false); - var g = lookup.GetGrouping(outerKey, create: false); + var g = lookup.GetGrouping(outerKey); if (g != null) { @@ -123,7 +123,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) internal static IAsyncEnumerable JoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector) => JoinAwaitWithCancellationCore(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer: null); - internal static IAsyncEnumerable JoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector, IEqualityComparer comparer) + internal static IAsyncEnumerable JoinAwaitWithCancellationCore(this IAsyncEnumerable outer, IAsyncEnumerable inner, Func> outerKeySelector, Func> innerKeySelector, Func> resultSelector, IEqualityComparer? comparer) { if (outer == null) throw Error.ArgumentNull(nameof(outer)); @@ -154,7 +154,7 @@ async IAsyncEnumerator Core(CancellationToken cancellationToken) var outerKey = await outerKeySelector(item, cancellationToken).ConfigureAwait(false); - var g = lookup.GetGrouping(outerKey, create: false); + var g = lookup.GetGrouping(outerKey); if (g != null) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs index f7edf0230c..c076682fb4 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/LastOrDefault.cs @@ -21,7 +21,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { var last = await TryGetLast(source, cancellationToken).ConfigureAwait(false); - return last.HasValue ? last.Value : default; + return last.HasValue ? last.Value : default!; } } @@ -38,7 +38,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func> TryGetLast(IAsyncEnumerable> Core(IAsyncEnumerable source, CancellationToken cancellationToken) { - var last = default(TSource); + var last = default(TSource)!; // NB: Only matters when hasLast is set to true. var hasLast = false; await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -107,7 +107,7 @@ static async ValueTask> Core(IAsyncEnumerable source, Ca last = item; } - return hasLast ? new Maybe(last) : new Maybe(); + return hasLast ? new Maybe(last!) : new Maybe(); } } @@ -116,7 +116,7 @@ static async ValueTask> Core(IAsyncEnumerable source, Ca private static async ValueTask> TryGetLast(IAsyncEnumerable source, Func predicate, CancellationToken cancellationToken) { - var last = default(TSource); + var last = default(TSource)!; // NB: Only matters when hasLast is set to true. var hasLast = false; await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -128,12 +128,12 @@ private static async ValueTask> TryGetLast(IAsyncEnumera } } - return hasLast ? new Maybe(last) : new Maybe(); + return hasLast ? new Maybe(last!) : new Maybe(); } private static async ValueTask> TryGetLast(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) { - var last = default(TSource); + var last = default(TSource)!; // NB: Only matters when hasLast is set to true. var hasLast = false; await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -145,13 +145,13 @@ private static async ValueTask> TryGetLast(IAsyncEnumera } } - return hasLast ? new Maybe(last) : new Maybe(); + return hasLast ? new Maybe(last!) : new Maybe(); } #if !NO_DEEP_CANCELLATION private static async ValueTask> TryGetLast(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) { - var last = default(TSource); + var last = default(TSource)!; // NB: Only matters when hasLast is set to true. var hasLast = false; await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) @@ -163,7 +163,7 @@ private static async ValueTask> TryGetLast(IAsyncEnumera } } - return hasLast ? new Maybe(last) : new Maybe(); + return hasLast ? new Maybe(last!) : new Maybe(); } #endif } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs index 48815e8d4f..e722973dda 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Lookup.cs @@ -16,9 +16,9 @@ internal class Lookup : ILookup, IAsyncIListProv { private readonly IEqualityComparer _comparer; private Grouping[] _groupings; - private Grouping _lastGrouping; + private Grouping? _lastGrouping; - private Lookup(IEqualityComparer comparer) + private Lookup(IEqualityComparer? comparer) { _comparer = comparer ?? EqualityComparer.Default; _groupings = new Grouping[7]; @@ -30,7 +30,7 @@ public IEnumerable this[TKey key] { get { - var grouping = GetGrouping(key, create: false); + var grouping = GetGrouping(key); if (grouping != null) { return grouping; @@ -46,7 +46,7 @@ public IEnumerable this[TKey key] public bool Contains(TKey key) { - return GetGrouping(key, create: false) != null; + return GetGrouping(key) != null; } IEnumerator IEnumerable.GetEnumerator() @@ -61,8 +61,8 @@ public IEnumerator> GetEnumerator() { do { - g = g._next; - yield return g; + g = g!._next; + yield return g!; } while (g != _lastGrouping); } } @@ -75,7 +75,7 @@ public IEnumerable ApplyResultSelector(Func ApplyResultSelector(Func> CreateAsync(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -94,7 +94,7 @@ internal static async Task> CreateAsync(IAsyncEn await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = keySelector(item); - var group = lookup.GetGrouping(key, create: true); + var group = lookup.GetOrCreateGrouping(key); var element = elementSelector(item); group.Add(element); @@ -103,7 +103,7 @@ internal static async Task> CreateAsync(IAsyncEn return lookup; } - internal static async Task> CreateAsync(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -113,13 +113,13 @@ internal static async Task> CreateAsync(IAsyncEnumerable< await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = keySelector(item); - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } return lookup; } - internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var lookup = new Lookup(comparer); @@ -128,16 +128,22 @@ internal static async Task> CreateForJoinAsync(IAsyncEnum var key = keySelector(item); if (key != null) { - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } } return lookup; } - internal Grouping GetGrouping(TKey key, bool create) + internal Grouping? GetGrouping(TKey key) { var hashCode = InternalGetHashCode(key); + + return GetGrouping(key, hashCode); + } + + internal Grouping? GetGrouping(TKey key, int hashCode) + { for (var g = _groupings[hashCode % _groupings.Length]; g != null; g = g._hashNext) { if (g._hashCode == hashCode && _comparer.Equals(g._key, key)) @@ -146,38 +152,40 @@ internal Grouping GetGrouping(TKey key, bool create) } } - if (create) + return null; + } + + internal Grouping GetOrCreateGrouping(TKey key) + { + var hashCode = InternalGetHashCode(key); + + var grouping = GetGrouping(key, hashCode); + if (grouping != null) { - if (Count == _groupings.Length) - { - Resize(); - } + return grouping; + } - var index = hashCode % _groupings.Length; - var g = new Grouping - { - _key = key, - _hashCode = hashCode, - _elements = new TElement[1], - _hashNext = _groupings[index] - }; - _groupings[index] = g; - if (_lastGrouping == null) - { - g._next = g; - } - else - { - g._next = _lastGrouping._next; - _lastGrouping._next = g; - } + if (Count == _groupings.Length) + { + Resize(); + } - _lastGrouping = g; - Count++; - return g; + var index = hashCode % _groupings.Length; + var g = new Grouping(key, hashCode, new TElement[1], _groupings[index]); + _groupings[index] = g; + if (_lastGrouping == null) + { + g._next = g; + } + else + { + g._next = _lastGrouping._next; + _lastGrouping._next = g; } - return null; + _lastGrouping = g; + Count++; + return g; } internal int InternalGetHashCode(TKey key) @@ -196,7 +204,7 @@ internal TResult[] ToArray(Func, TResu do { g = g._next; - g.Trim(); + g!.Trim(); array[index] = resultSelector(g._key, g._elements.ToAsyncEnumerable()); ++index; } while (g != _lastGrouping); @@ -214,7 +222,7 @@ internal List ToList(Func, TR do { g = g._next; - g.Trim(); + g!.Trim(); var result = resultSelector(g._key, g._elements.ToAsyncEnumerable()); list.Add(result); @@ -231,8 +239,8 @@ private void Resize() var g = _lastGrouping; do { - g = g._next; - var index = g._hashCode % newSize; + g = g!._next; + var index = g!._hashCode % newSize; g._hashNext = newGroupings[index]; newGroupings[index] = g; } while (g != _lastGrouping); @@ -262,8 +270,8 @@ ValueTask>> IAsyncIListProvider[]> IAsyncIListProvider : ILookup, IAsyncI { private readonly IEqualityComparer _comparer; private Grouping[] _groupings; - private Grouping _lastGrouping; + private Grouping? _lastGrouping; - private LookupWithTask(IEqualityComparer comparer) + private LookupWithTask(IEqualityComparer? comparer) { _comparer = comparer ?? EqualityComparer.Default; _groupings = new Grouping[7]; @@ -311,7 +319,7 @@ public IEnumerable this[TKey key] { get { - var grouping = GetGrouping(key, create: false); + var grouping = GetGrouping(key); if (grouping != null) { return grouping; @@ -327,7 +335,7 @@ public IEnumerable this[TKey key] public bool Contains(TKey key) { - return GetGrouping(key, create: false) != null; + return GetGrouping(key) != null; } IEnumerator IEnumerable.GetEnumerator() @@ -342,13 +350,13 @@ public IEnumerator> GetEnumerator() { do { - g = g._next; - yield return g; + g = g!._next; + yield return g!; } while (g != _lastGrouping); } } - internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -359,7 +367,7 @@ internal static async Task> CreateAsync( await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = await keySelector(item).ConfigureAwait(false); - var group = lookup.GetGrouping(key, create: true); + var group = lookup.GetOrCreateGrouping(key); var element = await elementSelector(item).ConfigureAwait(false); group.Add(element); @@ -369,7 +377,7 @@ internal static async Task> CreateAsync( } #if !NO_DEEP_CANCELLATION - internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -380,7 +388,7 @@ internal static async Task> CreateAsync( await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = await keySelector(item, cancellationToken).ConfigureAwait(false); - var group = lookup.GetGrouping(key, create: true); + var group = lookup.GetOrCreateGrouping(key); var element = await elementSelector(item, cancellationToken).ConfigureAwait(false); group.Add(element); @@ -390,7 +398,7 @@ internal static async Task> CreateAsync( } #endif - internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -400,14 +408,14 @@ internal static async Task> CreateAsync(IAsyncEnu await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = await keySelector(item).ConfigureAwait(false); - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } return lookup; } #if !NO_DEEP_CANCELLATION - internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { Debug.Assert(source != null); Debug.Assert(keySelector != null); @@ -417,14 +425,14 @@ internal static async Task> CreateAsync(IAsyncEnu await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false)) { var key = await keySelector(item, cancellationToken).ConfigureAwait(false); - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } return lookup; } #endif - internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var lookup = new LookupWithTask(comparer); @@ -433,7 +441,7 @@ internal static async Task> CreateForJoinAsync(IA var key = await keySelector(item).ConfigureAwait(false); if (key != null) { - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } } @@ -441,7 +449,7 @@ internal static async Task> CreateForJoinAsync(IA } #if !NO_DEEP_CANCELLATION - internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + internal static async Task> CreateForJoinAsync(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var lookup = new LookupWithTask(comparer); @@ -450,7 +458,7 @@ internal static async Task> CreateForJoinAsync(IA var key = await keySelector(item, cancellationToken).ConfigureAwait(false); if (key != null) { - lookup.GetGrouping(key, create: true).Add(item); + lookup.GetOrCreateGrouping(key).Add(item); } } @@ -458,9 +466,15 @@ internal static async Task> CreateForJoinAsync(IA } #endif - internal Grouping GetGrouping(TKey key, bool create) + internal Grouping? GetGrouping(TKey key) { var hashCode = InternalGetHashCode(key); + + return GetGrouping(key, hashCode); + } + + internal Grouping? GetGrouping(TKey key, int hashCode) + { for (var g = _groupings[hashCode % _groupings.Length]; g != null; g = g._hashNext) { if (g._hashCode == hashCode && _comparer.Equals(g._key, key)) @@ -469,38 +483,40 @@ internal Grouping GetGrouping(TKey key, bool create) } } - if (create) + return null; + } + + internal Grouping GetOrCreateGrouping(TKey key) + { + var hashCode = InternalGetHashCode(key); + + var grouping = GetGrouping(key, hashCode); + if (grouping != null) { - if (Count == _groupings.Length) - { - Resize(); - } + return grouping; + } - var index = hashCode % _groupings.Length; - var g = new Grouping - { - _key = key, - _hashCode = hashCode, - _elements = new TElement[1], - _hashNext = _groupings[index] - }; - _groupings[index] = g; - if (_lastGrouping == null) - { - g._next = g; - } - else - { - g._next = _lastGrouping._next; - _lastGrouping._next = g; - } + if (Count == _groupings.Length) + { + Resize(); + } - _lastGrouping = g; - Count++; - return g; + var index = hashCode % _groupings.Length; + var g = new Grouping(key, hashCode, new TElement[1], _groupings[index]); + _groupings[index] = g; + if (_lastGrouping == null) + { + g._next = g; + } + else + { + g._next = _lastGrouping._next; + _lastGrouping._next = g; } - return null; + _lastGrouping = g; + Count++; + return g; } internal int InternalGetHashCode(TKey key) @@ -519,7 +535,7 @@ internal async Task ToArray(Func ToArray(Func> ToList(Func> ToList(Func>> IAsyncIListProvider[]> IAsyncIListProvider MaxAsync(this IAsyncEnumerable Core(IAsyncEnumerable source, Cancellat { var comparer = Comparer.Default; - var value = default(TSource); + TSource value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -31,7 +31,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { if (!await e.MoveNextAsync()) { - return value; + return default!; } value = e.Current; @@ -60,7 +60,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { var comparer = Comparer.Default; - var value = default(TSource); + TSource value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -93,7 +93,7 @@ public static ValueTask MaxAsync(this IAsyncEnumerabl if (selector == null) throw Error.ArgumentNull(nameof(selector)); - if (default(TResult) == null) + if (default(TResult)! == null) // NB: Null value is desired; JIT-time check. { return Core(source, selector, cancellationToken); @@ -101,7 +101,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -109,7 +109,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -171,7 +171,7 @@ internal static ValueTask MaxAwaitAsyncCore(this IAsy if (selector == null) throw Error.ArgumentNull(nameof(selector)); - if (default(TResult) == null) + if (default(TResult)! == null) // NB: Null value is desired; JIT-time check. { return Core(source, selector, cancellationToken); @@ -179,7 +179,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -187,7 +187,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -251,7 +251,7 @@ internal static ValueTask MaxAwaitWithCancellationAsyncCore Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -267,7 +267,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs index ebde269817..5bbdbfb75d 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Min.cs @@ -15,7 +15,7 @@ public static ValueTask MinAsync(this IAsyncEnumerable Core(IAsyncEnumerable source, Cancellat { var comparer = Comparer.Default; - var value = default(TSource); + TSource value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -31,7 +31,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { if (!await e.MoveNextAsync()) { - return value; + return default!; } value = e.Current; @@ -60,7 +60,7 @@ static async ValueTask Core(IAsyncEnumerable source, Cancellat { var comparer = Comparer.Default; - var value = default(TSource); + TSource value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -94,7 +94,7 @@ public static ValueTask MinAsync(this IAsyncEnumerabl if (selector == null) throw Error.ArgumentNull(nameof(selector)); - if (default(TResult) == null) + if (default(TResult)! == null) // NB: Null value is desired; JIT-time check. { return Core(source, selector, cancellationToken); @@ -102,7 +102,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -110,7 +110,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -173,7 +173,7 @@ internal static ValueTask MinAwaitAsyncCore(this IAsy if (selector == null) throw Error.ArgumentNull(nameof(selector)); - if (default(TResult) == null) + if (default(TResult)! == null) // NB: Null value is desired; JIT-time check. { return Core(source, selector, cancellationToken); @@ -181,7 +181,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -189,7 +189,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -253,7 +253,7 @@ internal static ValueTask MinAwaitWithCancellationAsyncCore Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -269,7 +269,7 @@ static async ValueTask Core(IAsyncEnumerable source, Func Core(IAsyncEnumerable source, Func.Default; - var value = default(TResult); + TResult value; await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs index 0eead0ae6c..8453209c6f 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs @@ -15,8 +15,8 @@ internal abstract class OrderedAsyncEnumerable : AsyncIterator _source; - private TElement[] _buffer; - private int[] _indexes; + private TElement[]? _buffer; + private int[]? _indexes; private int _index; protected OrderedAsyncEnumerable(IAsyncEnumerable source) @@ -24,17 +24,17 @@ protected OrderedAsyncEnumerable(IAsyncEnumerable source) _source = source ?? throw Error.ArgumentNull(nameof(source)); } - IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func keySelector, IComparer comparer, bool descending) + IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func keySelector, IComparer? comparer, bool descending) { return new OrderedAsyncEnumerable(_source, keySelector, comparer, descending, this); } - IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func> keySelector, IComparer comparer, bool descending) + IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func> keySelector, IComparer? comparer, bool descending) { return new OrderedAsyncEnumerableWithTask(_source, keySelector, comparer, descending, this); } - IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func> keySelector, IComparer comparer, bool descending) + IOrderedAsyncEnumerable IOrderedAsyncEnumerable.CreateOrderedEnumerable(Func> keySelector, IComparer? comparer, bool descending) { return new OrderedAsyncEnumerableWithTaskAndCancellation(_source, keySelector, comparer, descending, this); } @@ -54,9 +54,9 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_index < _buffer.Length) + if (_index < _buffer!.Length) { - _current = _buffer[_indexes[_index++]]; + _current = _buffer[_indexes![_index++]]; return true; } @@ -75,7 +75,7 @@ public override async ValueTask DisposeAsync() await base.DisposeAsync().ConfigureAwait(false); } - internal abstract AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter next, CancellationToken cancellationToken); + internal abstract AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter? next, CancellationToken cancellationToken); internal AsyncEnumerableSorter GetAsyncEnumerableSorter(CancellationToken cancellationToken) => GetAsyncEnumerableSorter(next: null, cancellationToken); @@ -260,7 +260,7 @@ private ValueTask SortedMap(TElement[] elements, int count, int minIndexI private AsyncCachingComparer GetComparer() => GetComparer(childComparer: null); - internal abstract AsyncCachingComparer GetComparer(AsyncCachingComparer childComparer); + internal abstract AsyncCachingComparer GetComparer(AsyncCachingComparer? childComparer); public async ValueTask> TryGetFirstAsync(CancellationToken cancellationToken) { @@ -413,9 +413,9 @@ internal sealed class OrderedAsyncEnumerable : OrderedAsyncEnume private readonly IComparer _comparer; private readonly bool _descending; private readonly Func _keySelector; - private readonly OrderedAsyncEnumerable _parent; + private readonly OrderedAsyncEnumerable? _parent; - public OrderedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, IComparer comparer, bool descending, OrderedAsyncEnumerable parent) + public OrderedAsyncEnumerable(IAsyncEnumerable source, Func keySelector, IComparer? comparer, bool descending, OrderedAsyncEnumerable? parent) : base(source) { _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -429,7 +429,7 @@ public override AsyncIteratorBase Clone() return new OrderedAsyncEnumerable(_source, _keySelector, _comparer, _descending, _parent); } - internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter next, CancellationToken cancellationToken) + internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter? next, CancellationToken cancellationToken) { var sorter = new SyncKeySelectorAsyncEnumerableSorter(_keySelector, _comparer, _descending, next); @@ -441,7 +441,7 @@ internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(Async return sorter; } - internal override AsyncCachingComparer GetComparer(AsyncCachingComparer childComparer) + internal override AsyncCachingComparer GetComparer(AsyncCachingComparer? childComparer) { AsyncCachingComparer cmp = childComparer == null ? new AsyncCachingComparer(_keySelector, _comparer, _descending) @@ -456,9 +456,9 @@ internal sealed class OrderedAsyncEnumerableWithTask : OrderedAs private readonly IComparer _comparer; private readonly bool _descending; private readonly Func> _keySelector; - private readonly OrderedAsyncEnumerable _parent; + private readonly OrderedAsyncEnumerable? _parent; - public OrderedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, IComparer comparer, bool descending, OrderedAsyncEnumerable parent) + public OrderedAsyncEnumerableWithTask(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, bool descending, OrderedAsyncEnumerable? parent) : base(source) { _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -472,7 +472,7 @@ public override AsyncIteratorBase Clone() return new OrderedAsyncEnumerableWithTask(_source, _keySelector, _comparer, _descending, _parent); } - internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter next, CancellationToken cancellationToken) + internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter? next, CancellationToken cancellationToken) { var sorter = new AsyncKeySelectorAsyncEnumerableSorter(_keySelector, _comparer, _descending, next); @@ -484,7 +484,7 @@ internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(Async return sorter; } - internal override AsyncCachingComparer GetComparer(AsyncCachingComparer childComparer) + internal override AsyncCachingComparer GetComparer(AsyncCachingComparer? childComparer) { AsyncCachingComparer cmp = childComparer == null ? new AsyncCachingComparerWithTask(_keySelector, _comparer, _descending) @@ -500,9 +500,9 @@ internal sealed class OrderedAsyncEnumerableWithTaskAndCancellation _comparer; private readonly bool _descending; private readonly Func> _keySelector; - private readonly OrderedAsyncEnumerable _parent; + private readonly OrderedAsyncEnumerable? _parent; - public OrderedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IComparer comparer, bool descending, OrderedAsyncEnumerable parent) + public OrderedAsyncEnumerableWithTaskAndCancellation(IAsyncEnumerable source, Func> keySelector, IComparer? comparer, bool descending, OrderedAsyncEnumerable? parent) : base(source) { _keySelector = keySelector ?? throw Error.ArgumentNull(nameof(keySelector)); @@ -516,7 +516,7 @@ public override AsyncIteratorBase Clone() return new OrderedAsyncEnumerableWithTaskAndCancellation(_source, _keySelector, _comparer, _descending, _parent); } - internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter next, CancellationToken cancellationToken) + internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(AsyncEnumerableSorter? next, CancellationToken cancellationToken) { var sorter = new AsyncKeySelectorAsyncEnumerableSorterWithCancellation(_keySelector, _comparer, _descending, next, cancellationToken); @@ -528,7 +528,7 @@ internal override AsyncEnumerableSorter GetAsyncEnumerableSorter(Async return sorter; } - internal override AsyncCachingComparer GetComparer(AsyncCachingComparer childComparer) + internal override AsyncCachingComparer GetComparer(AsyncCachingComparer? childComparer) { AsyncCachingComparer cmp = childComparer == null ? new AsyncCachingComparerWithTaskAndCancellation(_keySelector, _comparer, _descending) @@ -599,10 +599,10 @@ internal abstract class AsyncEnumerableSorterBase : AsyncEnumera { private readonly IComparer _comparer; private readonly bool _descending; - protected readonly AsyncEnumerableSorter _next; - protected TKey[] _keys; + protected readonly AsyncEnumerableSorter? _next; + protected TKey[]? _keys; - public AsyncEnumerableSorterBase(IComparer comparer, bool descending, AsyncEnumerableSorter next) + public AsyncEnumerableSorterBase(IComparer comparer, bool descending, AsyncEnumerableSorter? next) { _comparer = comparer; _descending = descending; @@ -611,7 +611,7 @@ public AsyncEnumerableSorterBase(IComparer comparer, bool descending, Asyn internal sealed override int CompareAnyKeys(int index1, int index2) { - var c = _comparer.Compare(_keys[index1], _keys[index2]); + var c = _comparer.Compare(_keys![index1], _keys[index2]); // NB: _keys is assigned before calling this method. if (c == 0) { @@ -783,7 +783,7 @@ internal sealed class SyncKeySelectorAsyncEnumerableSorter : Asy { private readonly Func _keySelector; - public SyncKeySelectorAsyncEnumerableSorter(Func keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter next) + public SyncKeySelectorAsyncEnumerableSorter(Func keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter? next) : base(comparer, descending, next) { _keySelector = keySelector; @@ -809,7 +809,7 @@ internal sealed class AsyncKeySelectorAsyncEnumerableSorter : As { private readonly Func> _keySelector; - public AsyncKeySelectorAsyncEnumerableSorter(Func> keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter next) + public AsyncKeySelectorAsyncEnumerableSorter(Func> keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter? next) : base(comparer, descending, next) { _keySelector = keySelector; @@ -837,7 +837,7 @@ internal sealed class AsyncKeySelectorAsyncEnumerableSorterWithCancellation> _keySelector; private readonly CancellationToken _cancellationToken; - public AsyncKeySelectorAsyncEnumerableSorterWithCancellation(Func> keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter next, CancellationToken cancellationToken) + public AsyncKeySelectorAsyncEnumerableSorterWithCancellation(Func> keySelector, IComparer comparer, bool descending, AsyncEnumerableSorter? next, CancellationToken cancellationToken) : base(comparer, descending, next) { _keySelector = keySelector; @@ -927,8 +927,8 @@ public ValueTask> TryGetLastAsync(CancellationToken cancellation // REVIEW: Consider to tear off an iterator object rather than storing this state here? - private TElement[] _buffer; - private int[] _indexes; + private TElement[]? _buffer; + private int[]? _indexes; private int _minIndexIterator; private int _maxIndexIterator; @@ -978,7 +978,7 @@ protected override async ValueTask MoveNextCore() case AsyncIteratorState.Iterating: if (_minIndexIterator <= _maxIndexIterator) { - _current = _buffer[_indexes[_minIndexIterator++]]; + _current = _buffer![_indexes![_minIndexIterator++]]; return true; } @@ -1017,6 +1017,7 @@ public AsyncCachingComparer(Func keySelector, IComparer co _keySelector = keySelector; _comparer = comparer; _descending = descending; + _lastKey = default!; } internal override ValueTask Compare(TElement element, bool cacheLower, CancellationToken cancellationToken) @@ -1092,6 +1093,7 @@ public AsyncCachingComparerWithTask(Func> keySelector, _keySelector = keySelector; _comparer = comparer; _descending = descending; + _lastKey = default!; } internal override async ValueTask Compare(TElement element, bool cacheLower, CancellationToken cancellationToken) @@ -1166,6 +1168,7 @@ public AsyncCachingComparerWithTaskAndCancellation(Func Compare(TElement element, bool cacheLower, CancellationToken cancellationToken) diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Reverse.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Reverse.cs index 7c3cbfe510..affe7b5848 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Reverse.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Reverse.cs @@ -25,7 +25,7 @@ private sealed class ReverseAsyncIterator : AsyncIterator, IAs private readonly IAsyncEnumerable _source; private int _index; - private TSource[] _items; + private TSource[]? _items; public ReverseAsyncIterator(IAsyncEnumerable source) { @@ -101,7 +101,7 @@ protected override async ValueTask MoveNextCore() case AsyncIteratorState.Iterating: if (_index != -1) { - _current = _items[_index]; + _current = _items![_index]; --_index; return true; } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs index ab87e2b662..9feaf08867 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Select.cs @@ -149,7 +149,7 @@ internal sealed class SelectEnumerableAsyncIterator : AsyncIte private readonly Func _selector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public SelectEnumerableAsyncIterator(IAsyncEnumerable source, Func selector) { @@ -191,7 +191,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _selector(_enumerator.Current); return true; @@ -209,7 +209,7 @@ internal sealed class SelectIListIterator : AsyncIterator _selector; private readonly IList _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public SelectIListIterator(IList source, Func selector) { @@ -307,7 +307,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _selector(_enumerator.Current); return true; @@ -326,7 +326,7 @@ internal sealed class SelectEnumerableAsyncIteratorWithTask : private readonly Func> _selector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public SelectEnumerableAsyncIteratorWithTask(IAsyncEnumerable source, Func> selector) { @@ -368,7 +368,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = await _selector(_enumerator.Current).ConfigureAwait(false); return true; @@ -388,7 +388,7 @@ internal sealed class SelectEnumerableAsyncIteratorWithTaskAndCancellation> _selector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public SelectEnumerableAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable source, Func> selector) { @@ -430,7 +430,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = await _selector(_enumerator.Current, _cancellationToken).ConfigureAwait(false); return true; @@ -454,7 +454,7 @@ private sealed class SelectIListIteratorWithTask : AsyncIterat { private readonly Func> _selector; private readonly IList _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public SelectIListIteratorWithTask(IList source, Func> selector) { @@ -557,7 +557,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = await _selector(_enumerator.Current).ConfigureAwait(false); return true; @@ -576,7 +576,7 @@ private sealed class SelectIListIteratorWithTaskAndCancellation> _selector; private readonly IList _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public SelectIListIteratorWithTaskAndCancellation(IList source, Func> selector) { @@ -679,7 +679,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = await _selector(_enumerator.Current, _cancellationToken).ConfigureAwait(false); return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs index 5e6c9ecab7..c6fa5aaffc 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs @@ -321,8 +321,8 @@ private sealed class SelectManyAsyncIterator : AsyncIterator _source; private int _mode; - private IAsyncEnumerator _resultEnumerator; - private IAsyncEnumerator _sourceEnumerator; + private IAsyncEnumerator? _resultEnumerator; + private IAsyncEnumerator? _sourceEnumerator; public SelectManyAsyncIterator(IAsyncEnumerable source, Func> selector) { @@ -417,7 +417,7 @@ protected override async ValueTask MoveNextCore() switch (_mode) { case State_Source: - if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false)) { if (_resultEnumerator != null) { @@ -433,7 +433,7 @@ protected override async ValueTask MoveNextCore() break; case State_Result: - if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _resultEnumerator.Current; return true; @@ -460,8 +460,8 @@ private sealed class SelectManyAsyncIteratorWithTask : AsyncIt private readonly IAsyncEnumerable _source; private int _mode; - private IAsyncEnumerator _resultEnumerator; - private IAsyncEnumerator _sourceEnumerator; + private IAsyncEnumerator? _resultEnumerator; + private IAsyncEnumerator? _sourceEnumerator; public SelectManyAsyncIteratorWithTask(IAsyncEnumerable source, Func>> selector) { @@ -558,7 +558,7 @@ protected override async ValueTask MoveNextCore() switch (_mode) { case State_Source: - if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false)) { if (_resultEnumerator != null) { @@ -574,7 +574,7 @@ protected override async ValueTask MoveNextCore() break; case State_Result: - if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _resultEnumerator.Current; return true; @@ -602,8 +602,8 @@ private sealed class SelectManyAsyncIteratorWithTaskAndCancellation _source; private int _mode; - private IAsyncEnumerator _resultEnumerator; - private IAsyncEnumerator _sourceEnumerator; + private IAsyncEnumerator? _resultEnumerator; + private IAsyncEnumerator? _sourceEnumerator; public SelectManyAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable source, Func>> selector) { @@ -700,7 +700,7 @@ protected override async ValueTask MoveNextCore() switch (_mode) { case State_Source: - if (await _sourceEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _sourceEnumerator!.MoveNextAsync().ConfigureAwait(false)) { if (_resultEnumerator != null) { @@ -716,7 +716,7 @@ protected override async ValueTask MoveNextCore() break; case State_Result: - if (await _resultEnumerator.MoveNextAsync().ConfigureAwait(false)) + if (await _resultEnumerator!.MoveNextAsync().ConfigureAwait(false)) { _current = _resultEnumerator.Current; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs index 089df17600..5fcf8142ab 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SequenceEqual.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable public static ValueTask SequenceEqualAsync(this IAsyncEnumerable first, IAsyncEnumerable second, CancellationToken cancellationToken = default) => SequenceEqualAsync(first, second, comparer: null, cancellationToken); - public static ValueTask SequenceEqualAsync(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask SequenceEqualAsync(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (first == null) throw Error.ArgumentNull(nameof(first)); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs index 0b0cc56592..e239f60363 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleLinkedNode.cs @@ -44,7 +44,7 @@ private SingleLinkedNode(SingleLinkedNode linked, TSource item) /// /// The next node in the singly-linked list. /// - public SingleLinkedNode Linked { get; } + public SingleLinkedNode? Linked { get; } /// /// Creates a new node that holds the specified item and is linked to this node. @@ -58,7 +58,7 @@ private SingleLinkedNode(SingleLinkedNode linked, TSource item) public int GetCount() { var count = 0; - for (var node = this; node != null; node = node.Linked) + for (SingleLinkedNode? node = this; node != null; node = node.Linked) { count++; } @@ -86,10 +86,10 @@ public SingleLinkedNode GetNode(int index) { Debug.Assert(index >= 0 && index < GetCount()); - var node = this; + SingleLinkedNode? node = this; for (; index > 0; index--) { - node = node.Linked; + node = node!.Linked; } Debug.Assert(node != null); @@ -106,7 +106,7 @@ private TSource[] ToArray(int count) var array = new TSource[count]; var index = count; - for (var node = this; node != null; node = node.Linked) + for (SingleLinkedNode? node = this; node != null; node = node.Linked) { --index; array[index] = node.Item; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs index cd13796723..420746052b 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SingleOrDefault.cs @@ -17,13 +17,13 @@ public static ValueTask SingleOrDefaultAsync(this IAsyncEnumer return Core(source, cancellationToken); - async ValueTask Core(IAsyncEnumerable source, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, CancellationToken cancellationToken) { if (source is IList list) { switch (list.Count) { - case 0: return default; + case 0: return default!; case 1: return list[0]; } @@ -34,7 +34,7 @@ async ValueTask Core(IAsyncEnumerable source, CancellationToke { if (!await e.MoveNextAsync()) { - return default; + return default!; } var result = e.Current; @@ -58,7 +58,7 @@ public static ValueTask SingleOrDefaultAsync(this IAsyncEnumer return Core(source, predicate, cancellationToken); - async ValueTask Core(IAsyncEnumerable source, Func predicate, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, Func predicate, CancellationToken cancellationToken) { await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -81,7 +81,7 @@ async ValueTask Core(IAsyncEnumerable source, Func SingleOrDefaultAwaitAsyncCore(this I return Core(source, predicate, cancellationToken); - async ValueTask Core(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) { await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -117,7 +117,7 @@ async ValueTask Core(IAsyncEnumerable source, Func SingleOrDefaultAwaitWithCancellationAsyncCore return Core(source, predicate, cancellationToken); - async ValueTask Core(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) + static async ValueTask Core(IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken) { await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false)) { @@ -154,7 +154,7 @@ async ValueTask Core(IAsyncEnumerable source, Func : AsyncIterator { private readonly IObservable _source; - private ConcurrentQueue _values = new ConcurrentQueue(); - private Exception _error; + private ConcurrentQueue? _values = new ConcurrentQueue(); + private Exception? _error; private bool _completed; - private TaskCompletionSource _signal; - private IDisposable _subscription; + private TaskCompletionSource? _signal; + private IDisposable? _subscription; private CancellationTokenRegistration _ctr; public ObservableAsyncEnumerable(IObservable source) => _source = source; @@ -78,7 +78,7 @@ protected override async ValueTask MoveNextCore() { var completed = Volatile.Read(ref _completed); - if (_values.TryDequeue(out _current)) + if (_values!.TryDequeue(out _current)) { return true; } @@ -166,7 +166,7 @@ private void Dispose() private Task Resume() { - TaskCompletionSource newSignal = null; + TaskCompletionSource? newSignal = null; while (true) { @@ -177,10 +177,7 @@ private Task Resume() return signal.Task; } - if (newSignal == null) - { - newSignal = new TaskCompletionSource(); - } + newSignal ??= new TaskCompletionSource(); if (Interlocked.CompareExchange(ref _signal, newSignal, null) == null) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs index 3b65f6f0bb..4387d0a362 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToAsyncEnumerable.cs @@ -32,7 +32,7 @@ private sealed class AsyncEnumerableAdapter : AsyncIterator, IAsyncIListPr { private readonly IEnumerable _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public AsyncEnumerableAdapter(IEnumerable source) { @@ -64,7 +64,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _enumerator.Current; return true; @@ -107,7 +107,7 @@ public ValueTask GetCountAsync(bool onlyIfCheap, CancellationToken cancella private sealed class AsyncIListEnumerableAdapter : AsyncIterator, IAsyncIListProvider, IList { private readonly IList _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public AsyncIListEnumerableAdapter(IList source) { @@ -139,7 +139,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _enumerator.Current; return true; @@ -214,7 +214,7 @@ T IList.this[int index] private sealed class AsyncICollectionEnumerableAdapter : AsyncIterator, IAsyncIListProvider, ICollection { private readonly ICollection _source; - private IEnumerator _enumerator; + private IEnumerator? _enumerator; public AsyncICollectionEnumerableAdapter(ICollection source) { @@ -246,7 +246,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - if (_enumerator.MoveNext()) + if (_enumerator!.MoveNext()) { _current = _enumerator.Current; return true; diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs index 22677c538b..c12b816f42 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToDictionary.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, CancellationToken cancellationToken = default) => ToDictionaryAsync(source, keySelector, comparer: null, cancellationToken); - public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -22,7 +22,7 @@ public static ValueTask> ToDictionaryAsync> Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); @@ -40,7 +40,7 @@ static async ValueTask> Core(IAsyncEnumerable internal static ValueTask> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToDictionaryAwaitAsyncCore(source, keySelector, comparer: null, cancellationToken); - internal static ValueTask> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -49,7 +49,7 @@ internal static ValueTask> ToDictionaryAwaitAsyncCore< return Core(source, keySelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); @@ -68,7 +68,7 @@ static async ValueTask> Core(IAsyncEnumerable internal static ValueTask> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, comparer: null, cancellationToken); - internal static ValueTask> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -77,7 +77,7 @@ internal static ValueTask> ToDictionaryAwaitWithCancel return Core(source, keySelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); @@ -96,7 +96,7 @@ static async ValueTask> Core(IAsyncEnumerable public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, CancellationToken cancellationToken = default) => ToDictionaryAsync(source, keySelector, elementSelector, comparer: null, cancellationToken); - public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -107,7 +107,7 @@ public static ValueTask> ToDictionaryAsync> Core(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); @@ -126,7 +126,7 @@ static async ValueTask> Core(IAsyncEnumerable> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToDictionaryAwaitAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken); - internal static ValueTask> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToDictionaryAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -137,7 +137,7 @@ internal static ValueTask> ToDictionaryAwaitAsyncCore return Core(source, keySelector, elementSelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); @@ -157,7 +157,7 @@ static async ValueTask> Core(IAsyncEnumerable> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken); - internal static ValueTask> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToDictionaryAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -168,7 +168,7 @@ internal static ValueTask> ToDictionaryAwaitWithCance return Core(source, keySelector, elementSelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { var d = new Dictionary(comparer); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs index 2d84b9b945..a3ad45a990 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs @@ -19,9 +19,9 @@ public static IEnumerable ToEnumerable(this IAsyncEnumerable Core(IAsyncEnumerable _source) + static IEnumerable Core(IAsyncEnumerable source) { - var e = _source.GetAsyncEnumerator(default); + var e = source.GetAsyncEnumerator(default); try { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToHashSet.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToHashSet.cs index 4ad6f2fe92..a1f8ab7d42 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToHashSet.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToHashSet.cs @@ -13,14 +13,14 @@ public static partial class AsyncEnumerable public static ValueTask> ToHashSetAsync(this IAsyncEnumerable source, CancellationToken cancellationToken = default) => ToHashSetAsync(source, comparer: null, cancellationToken); - public static ValueTask> ToHashSetAsync(this IAsyncEnumerable source, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToHashSetAsync(this IAsyncEnumerable source, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); return Core(source, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, IEqualityComparer? comparer, CancellationToken cancellationToken) { var set = new HashSet(comparer); diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs index f49dd7c105..f2cafa0845 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToLookup.cs @@ -13,7 +13,7 @@ public static partial class AsyncEnumerable public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, CancellationToken cancellationToken = default) => ToLookupAsync(source, keySelector, comparer: null, cancellationToken); - public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -22,7 +22,7 @@ public static ValueTask> ToLookupAsync(thi return Core(source, keySelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.Lookup.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false); } @@ -31,7 +31,7 @@ static async ValueTask> Core(IAsyncEnumerable so internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, comparer:null, cancellationToken); - internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -40,7 +40,7 @@ internal static ValueTask> ToLookupAwaitAsyncCore> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.LookupWithTask.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false); } @@ -50,7 +50,7 @@ async ValueTask> Core(IAsyncEnumerable source, F internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, comparer: null, cancellationToken); - internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -59,7 +59,7 @@ internal static ValueTask> ToLookupAwaitWithCancellationA return Core(source, keySelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.LookupWithTask.CreateAsync(source, keySelector, comparer, cancellationToken).ConfigureAwait(false); } @@ -69,7 +69,7 @@ static async ValueTask> Core(IAsyncEnumerable so public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, CancellationToken cancellationToken = default) => ToLookupAsync(source, keySelector, elementSelector, comparer: null, cancellationToken); - public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -80,7 +80,7 @@ public static ValueTask> ToLookupAsync> Core(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.Lookup.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false); } @@ -89,7 +89,7 @@ static async ValueTask> Core(IAsyncEnumerable s internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken); - internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToLookupAwaitAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -100,7 +100,7 @@ internal static ValueTask> ToLookupAwaitAsyncCore> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.LookupWithTask.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false); } @@ -110,7 +110,7 @@ static async ValueTask> Core(IAsyncEnumerable s internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer: null, cancellationToken); - internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) + internal static ValueTask> ToLookupAwaitWithCancellationAsyncCore(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken = default) { if (source == null) throw Error.ArgumentNull(nameof(source)); @@ -121,7 +121,7 @@ internal static ValueTask> ToLookupAwaitWithCancellation return Core(source, keySelector, elementSelector, comparer, cancellationToken); - static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken) + static async ValueTask> Core(IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer? comparer, CancellationToken cancellationToken) { return await Internal.LookupWithTask.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false); } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs index 338da0ed4e..f042bdc154 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Union.cs @@ -14,7 +14,7 @@ public static partial class AsyncEnumerable public static IAsyncEnumerable Union(this IAsyncEnumerable first, IAsyncEnumerable second) => Union(first, second, comparer: null); - public static IAsyncEnumerable Union(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer comparer) + public static IAsyncEnumerable Union(this IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer) { if (first == null) throw Error.ArgumentNull(nameof(first)); @@ -24,7 +24,7 @@ public static IAsyncEnumerable Union(this IAsyncEnumerable union && AreEqualityComparersEqual(comparer, union._comparer) ? union.Union(second) : new UnionAsyncIterator2(first, second, comparer); } - private static bool AreEqualityComparersEqual(IEqualityComparer first, IEqualityComparer second) + private static bool AreEqualityComparersEqual(IEqualityComparer? first, IEqualityComparer? second) { return first == second || (first != null && second != null && first.Equals(second)); } @@ -35,12 +35,12 @@ private static bool AreEqualityComparersEqual(IEqualityComparerThe type of the source enumerables. private abstract class UnionAsyncIterator : AsyncIterator, IAsyncIListProvider { - internal readonly IEqualityComparer _comparer; - private IAsyncEnumerator _enumerator; - private Set _set; + internal readonly IEqualityComparer? _comparer; + private IAsyncEnumerator? _enumerator; + private Set? _set; private int _index; - protected UnionAsyncIterator(IEqualityComparer comparer) + protected UnionAsyncIterator(IEqualityComparer? comparer) { _comparer = comparer; } @@ -57,7 +57,7 @@ public sealed override async ValueTask DisposeAsync() await base.DisposeAsync().ConfigureAwait(false); } - internal abstract IAsyncEnumerable GetEnumerable(int index); + internal abstract IAsyncEnumerable? GetEnumerable(int index); internal abstract UnionAsyncIterator Union(IAsyncEnumerable next); @@ -74,7 +74,7 @@ private async Task SetEnumeratorAsync(IAsyncEnumerator enumerator) private void StoreFirst() { var set = new Set(_comparer); - var element = _enumerator.Current; + var element = _enumerator!.Current; set.Add(element); _current = element; _set = set; @@ -85,7 +85,7 @@ private async ValueTask GetNextAsync() var set = _set; Debug.Assert(set != null); - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { var element = _enumerator.Current; if (set.Add(element)) @@ -207,7 +207,7 @@ private sealed class UnionAsyncIterator2 : UnionAsyncIterator private readonly IAsyncEnumerable _first; private readonly IAsyncEnumerable _second; - public UnionAsyncIterator2(IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer comparer) + public UnionAsyncIterator2(IAsyncEnumerable first, IAsyncEnumerable second, IEqualityComparer? comparer) : base(comparer) { Debug.Assert(first != null); @@ -218,7 +218,7 @@ public UnionAsyncIterator2(IAsyncEnumerable first, IAsyncEnumerable Clone() => new UnionAsyncIterator2(_first, _second, _comparer); - internal override IAsyncEnumerable GetEnumerable(int index) + internal override IAsyncEnumerable? GetEnumerable(int index) { Debug.Assert(index >= 0 && index <= 2); switch (index) @@ -248,11 +248,11 @@ private sealed class UnionAsyncIteratorN : UnionAsyncIterator private readonly SingleLinkedNode> _sources; private readonly int _headIndex; - public UnionAsyncIteratorN(SingleLinkedNode> sources, int headIndex, IEqualityComparer comparer) + public UnionAsyncIteratorN(SingleLinkedNode> sources, int headIndex, IEqualityComparer? comparer) : base(comparer) { Debug.Assert(headIndex >= 2); - Debug.Assert(sources?.GetCount() == headIndex + 1); + Debug.Assert(sources.GetCount() == headIndex + 1); _sources = sources; _headIndex = headIndex; @@ -260,7 +260,7 @@ public UnionAsyncIteratorN(SingleLinkedNode> sources, public override AsyncIteratorBase Clone() => new UnionAsyncIteratorN(_sources, _headIndex, _comparer); - internal override IAsyncEnumerable GetEnumerable(int index) => index > _headIndex ? null : _sources.GetNode(_headIndex - index).Item; + internal override IAsyncEnumerable? GetEnumerable(int index) => index > _headIndex ? null : _sources.GetNode(_headIndex - index).Item; internal override UnionAsyncIterator Union(IAsyncEnumerable next) { diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs index e6ed892f83..a5da91edbf 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Where.cs @@ -151,7 +151,7 @@ internal sealed class WhereEnumerableAsyncIterator : AsyncIterator _predicate; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public WhereEnumerableAsyncIterator(IAsyncEnumerable source, Func predicate) { @@ -198,7 +198,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { var item = _enumerator.Current; if (_predicate(item)) @@ -220,7 +220,7 @@ internal sealed class WhereEnumerableAsyncIteratorWithTask : AsyncItera { private readonly Func> _predicate; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public WhereEnumerableAsyncIteratorWithTask(IAsyncEnumerable source, Func> predicate) { @@ -262,7 +262,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { var item = _enumerator.Current; if (await _predicate(item).ConfigureAwait(false)) @@ -285,7 +285,7 @@ internal sealed class WhereEnumerableAsyncIteratorWithTaskAndCancellation> _predicate; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public WhereEnumerableAsyncIteratorWithTaskAndCancellation(IAsyncEnumerable source, Func> predicate) { @@ -327,7 +327,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { var item = _enumerator.Current; if (await _predicate(item, _cancellationToken).ConfigureAwait(false)) @@ -352,7 +352,7 @@ private sealed class WhereSelectEnumerableAsyncIterator : Asyn private readonly Func _selector; private readonly IAsyncEnumerable _source; - private IAsyncEnumerator _enumerator; + private IAsyncEnumerator? _enumerator; public WhereSelectEnumerableAsyncIterator(IAsyncEnumerable source, Func predicate, Func selector) { @@ -396,7 +396,7 @@ protected override async ValueTask MoveNextCore() goto case AsyncIteratorState.Iterating; case AsyncIteratorState.Iterating: - while (await _enumerator.MoveNextAsync().ConfigureAwait(false)) + while (await _enumerator!.MoveNextAsync().ConfigureAwait(false)) { var item = _enumerator.Current; if (_predicate(item)) diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs index aa3286f005..d7c4776441 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Set.cs @@ -20,7 +20,7 @@ internal sealed class Set #endif private Slot[] _slots; - public Set(IEqualityComparer comparer) + public Set(IEqualityComparer? comparer) { _comparer = comparer ?? EqualityComparer.Default; _buckets = new int[7]; @@ -82,7 +82,7 @@ public bool Remove(TElement value) } _slots[i]._hashCode = -1; - _slots[i]._value = default; + _slots[i]._value = default!; _slots[i]._next = -1; return true; }