diff --git a/MoreLinq.Test/AggregateTest.cs b/MoreLinq.Test/AggregateTest.cs index 98b49e8b6..930522d58 100644 --- a/MoreLinq.Test/AggregateTest.cs +++ b/MoreLinq.Test/AggregateTest.cs @@ -121,8 +121,8 @@ public void SevenUniqueAccumulators() EvenSum = esum, Count = count, Average = (double)sum / count, - Min = min is {} mn ? mn : throw new InvalidOperationException(), - Max = max is {} mx ? mx : throw new InvalidOperationException(), + Min = min ?? throw new InvalidOperationException(), + Max = max ?? throw new InvalidOperationException(), UniqueLengths = lengths, Items = items, } diff --git a/MoreLinq.Test/FlattenTest.cs b/MoreLinq.Test/FlattenTest.cs index a416df347..2fe9e1f99 100644 --- a/MoreLinq.Test/FlattenTest.cs +++ b/MoreLinq.Test/FlattenTest.cs @@ -136,7 +136,7 @@ public void FlattenPredicate() 7, }; - var result = source.Flatten(obj => !(obj is IEnumerable)); + var result = source.Flatten(obj => obj is not IEnumerable); var expectations = new object[] { diff --git a/MoreLinq.Test/LeadTest.cs b/MoreLinq.Test/LeadTest.cs index e0d4c592d..041d27564 100644 --- a/MoreLinq.Test/LeadTest.cs +++ b/MoreLinq.Test/LeadTest.cs @@ -133,7 +133,7 @@ public void TestLeadPassesCorrectValueOffsetBy2() Assert.AreEqual(count, result.Count()); Assert.IsTrue(result.Take(count - 2).All(x => x.B == (x.A + 2))); - Assert.IsTrue(result.Skip(count - 2).All(x => x.B == leadDefault && (x.A == count || x.A == count - 1))); + Assert.IsTrue(result.Skip(count - 2).All(x => x.B == leadDefault && x.A is count or count - 1)); } [Test] diff --git a/MoreLinq.Test/MemoizeTest.cs b/MoreLinq.Test/MemoizeTest.cs index f2658fac2..80efcabf4 100644 --- a/MoreLinq.Test/MemoizeTest.cs +++ b/MoreLinq.Test/MemoizeTest.cs @@ -53,7 +53,7 @@ IEnumerable InnerForEach(IEnumerable source) { yield return i; - if (i == 3 || i == 7) + if (i is 3 or 7) { //consume 1-3 already cached //add 4-5 to cache (so go to outer loop) diff --git a/MoreLinq.Test/RandomTest.cs b/MoreLinq.Test/RandomTest.cs index 5f2bafdf0..54b295127 100644 --- a/MoreLinq.Test/RandomTest.cs +++ b/MoreLinq.Test/RandomTest.cs @@ -70,8 +70,8 @@ public void TestRandomDouble() // NOTE: Unclear what should actually be verified here... some additional thought needed. Assert.AreEqual(RandomTrials, resultA.Count()); Assert.AreEqual(RandomTrials, resultB.Count()); - Assert.IsTrue(resultA.All(x => x >= 0.0 && x < 1.0)); - Assert.IsTrue(resultB.All(x => x >= 0.0 && x < 1.0)); + Assert.IsTrue(resultA.All(x => x is >= 0.0 and < 1.0)); + Assert.IsTrue(resultB.All(x => x is >= 0.0 and < 1.0)); } /// @@ -103,8 +103,8 @@ public void TestRandomMinMaxConstraint() Assert.AreEqual(RandomTrials, resultA.Count()); Assert.AreEqual(RandomTrials, resultB.Count()); - Assert.IsTrue(resultA.All(x => x >= min && x < max)); - Assert.IsTrue(resultB.All(x => x >= min && x < max)); + Assert.IsTrue(resultA.All(x => x is >= min and < max)); + Assert.IsTrue(resultB.All(x => x is >= min and < max)); } /// diff --git a/MoreLinq.Test/TraceTest.cs b/MoreLinq.Test/TraceTest.cs index 0379c2f49..a95d87aa5 100644 --- a/MoreLinq.Test/TraceTest.cs +++ b/MoreLinq.Test/TraceTest.cs @@ -89,8 +89,7 @@ static IEnumerable Lines(string str) IEnumerator _(TextReader reader) { Debug.Assert(reader != null); - string line; - while ((line = reader.ReadLine()) != null) + while (reader.ReadLine() is { } line) yield return line; } } diff --git a/MoreLinq/Experimental/Await.cs b/MoreLinq/Experimental/Await.cs index e8fb18074..9b54d9e35 100644 --- a/MoreLinq/Experimental/Await.cs +++ b/MoreLinq/Experimental/Await.cs @@ -69,7 +69,7 @@ public sealed class AwaitQueryOptions AwaitQueryOptions(int? maxConcurrency, TaskScheduler scheduler, bool preserveOrder) { - MaxConcurrency = maxConcurrency == null || maxConcurrency > 0 + MaxConcurrency = maxConcurrency is null or > 0 ? maxConcurrency : throw new ArgumentOutOfRangeException( nameof(maxConcurrency), maxConcurrency, diff --git a/MoreLinq/FallbackIfEmpty.cs b/MoreLinq/FallbackIfEmpty.cs index 0d0fbc867..90256fcad 100644 --- a/MoreLinq/FallbackIfEmpty.cs +++ b/MoreLinq/FallbackIfEmpty.cs @@ -184,11 +184,11 @@ IEnumerable _() IEnumerable Fallback() { - return fallback is {} seq ? seq : FallbackOnArgs(); + return fallback ?? FallbackOnArgs(); IEnumerable FallbackOnArgs() { - Debug.Assert(count >= 1 && count <= 4); + Debug.Assert(count is >= 1 and <= 4); yield return fallback1!; if (count > 1) yield return fallback2!; diff --git a/MoreLinq/Flatten.cs b/MoreLinq/Flatten.cs index b1845ea43..8de35aaf7 100644 --- a/MoreLinq/Flatten.cs +++ b/MoreLinq/Flatten.cs @@ -41,7 +41,7 @@ public static IEnumerable< #nullable restore /*...................................*/ > Flatten(this IEnumerable source) => - Flatten(source, obj => !(obj is string)); + Flatten(source, obj => obj is not string); /// /// Flattens a sequence containing arbitrarily-nested sequences. An diff --git a/MoreLinq/Partition.cs b/MoreLinq/Partition.cs index 9066610f4..9bbf043d2 100644 --- a/MoreLinq/Partition.cs +++ b/MoreLinq/Partition.cs @@ -300,7 +300,7 @@ static TResult PartitionImpl(IEnumerable? comparer, Func, IEnumerable, IEnumerable, IEnumerable>, TResult> resultSelector) { - Debug.Assert(count > 0 && count <= 3); + Debug.Assert(count is > 0 and <= 3); if (source == null) throw new ArgumentNullException(nameof(source)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); diff --git a/MoreLinq/Split.cs b/MoreLinq/Split.cs index 93f52c22e..3ff9f2c97 100644 --- a/MoreLinq/Split.cs +++ b/MoreLinq/Split.cs @@ -292,7 +292,7 @@ public static IEnumerable Split(this IEnumerable 0) + if (items is { Count: > 0 }) yield return resultSelector(items); } } diff --git a/MoreLinq/Subsets.cs b/MoreLinq/Subsets.cs index 1491903bd..357a60f73 100644 --- a/MoreLinq/Subsets.cs +++ b/MoreLinq/Subsets.cs @@ -209,7 +209,7 @@ void ExtractSubset() public SubsetGenerator(IEnumerable sequence, int subsetSize) { - if (sequence == null) + if (sequence is null) throw new ArgumentNullException(nameof(sequence)); if (subsetSize < 0) throw new ArgumentOutOfRangeException(nameof(subsetSize), "{subsetSize} must be between 0 and set.Count()"); diff --git a/MoreLinq/ToDataTable.cs b/MoreLinq/ToDataTable.cs index bf309642e..d04c66d3c 100644 --- a/MoreLinq/ToDataTable.cs +++ b/MoreLinq/ToDataTable.cs @@ -164,7 +164,7 @@ MemberInfo GetAccessedMember(LambdaExpression lambda) var body = lambda.Body; // If it's a field access, boxing was used, we need the field - if (body.NodeType == ExpressionType.Convert || body.NodeType == ExpressionType.ConvertChecked) + if (body.NodeType is ExpressionType.Convert or ExpressionType.ConvertChecked) body = ((UnaryExpression)body).Operand; // Check if the member expression is valid and is a "first level" diff --git a/bld/ExtensionsGenerator/Program.cs b/bld/ExtensionsGenerator/Program.cs index 3b8c983bb..cd5b864d4 100644 --- a/bld/ExtensionsGenerator/Program.cs +++ b/bld/ExtensionsGenerator/Program.cs @@ -173,8 +173,8 @@ where md.ParameterList.Parameters.Count > 0 SortableParameterTypes = from p in md.ParameterList.Parameters select CreateTypeKey(p.Type, - n => typeParameterAbbreviationByName != null - && typeParameterAbbreviationByName.TryGetValue(n, out var a) ? a : null), + n => typeParameterAbbreviationByName is { } someTypeParameterAbbreviationByName + && someTypeParameterAbbreviationByName.TryGetValue(n, out var a) ? a : null), } } from e in ms.Select((m, i) => (SourceOrder: i + 1, Method: m)) @@ -385,8 +385,8 @@ abstract class TypeKey : IComparable public virtual int CompareTo(TypeKey other) => ReferenceEquals(this, other) ? 0 : other == null ? 1 - : Parameters.Count.CompareTo(other.Parameters.Count) is {} lc and not 0 ? lc - : string.Compare(Name, other.Name, StringComparison.Ordinal) is {} nc and not 0 ? nc + : Parameters.Count.CompareTo(other.Parameters.Count) is var lc and not 0 ? lc + : string.Compare(Name, other.Name, StringComparison.Ordinal) is var nc and not 0 ? nc : CompareParameters(other); protected virtual int CompareParameters(TypeKey other) => @@ -455,10 +455,10 @@ protected override int CompareParameters(TypeKey other) { if (other is ArrayTypeKey a) { - if (Ranks.Count.CompareTo(a.Ranks.Count) is {} rlc and not 0) + if (Ranks.Count.CompareTo(a.Ranks.Count) is var rlc and not 0) return rlc; if (Ranks.Zip(a.Ranks, (us, them) => (Us: us, Them: them)) - .Aggregate(0, (c, r) => c == 0 ? r.Us.CompareTo(r.Them) : c) is {} rc and not 0) + .Aggregate(0, (c, r) => c == 0 ? r.Us.CompareTo(r.Them) : c) is var rc and not 0) return rc; }