From 8b66c50933381ff30671d35acef6dcc7edc9bbd6 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 10:15:32 +0200 Subject: [PATCH] Replace explicit type mentions with object pattern --- MoreLinq.Test/AggregateTest.cs | 8 ++++---- MoreLinq.Test/ChooseTest.cs | 2 +- MoreLinq/AssertCount.cs | 2 +- MoreLinq/Backsert.cs | 2 +- MoreLinq/CountDown.cs | 4 ++-- MoreLinq/CountMethods.cs | 4 ++-- MoreLinq/EndsWith.cs | 4 ++-- MoreLinq/Experimental/Await.cs | 2 +- MoreLinq/Experimental/TrySingle.cs | 2 +- MoreLinq/FallbackIfEmpty.cs | 2 +- MoreLinq/Flatten.cs | 2 +- MoreLinq/PadStart.cs | 2 +- MoreLinq/SkipLast.cs | 2 +- MoreLinq/StartsWith.cs | 4 ++-- MoreLinq/TakeLast.cs | 2 +- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/MoreLinq.Test/AggregateTest.cs b/MoreLinq.Test/AggregateTest.cs index 55b531658..3a6ca3094 100644 --- a/MoreLinq.Test/AggregateTest.cs +++ b/MoreLinq.Test/AggregateTest.cs @@ -110,8 +110,8 @@ public void SevenUniqueAccumulators() 0, (s, e) => s + e.Num, 0, (s, e) => e.Num % 2 == 0 ? s + e.Num : s, 0, (s, _) => s + 1, - (int?)null, (s, e) => s is int n ? Math.Min(n, e.Num) : e.Num, - (int?)null, (s, e) => s is int n ? Math.Max(n, e.Num) : e.Num, + (int?)null, (s, e) => s is {} n ? Math.Min(n, e.Num) : e.Num, + (int?)null, (s, e) => s is {} n ? Math.Max(n, e.Num) : e.Num, new HashSet(), (s, e) => { s.Add(e.Str.Length); return s; }, new List<(int Num, string Str)>(), (s, e) => { s.Add((e.Num, e.Str)); return s; }, (sum, esum, count, min, max, lengths, items) => new @@ -120,8 +120,8 @@ public void SevenUniqueAccumulators() EvenSum = esum, Count = count, Average = (double)sum / count, - Min = min is int mn ? mn : throw new InvalidOperationException(), - Max = max is int mx ? mx : throw new InvalidOperationException(), + Min = min is {} mn ? mn : throw new InvalidOperationException(), + Max = max is {} mx ? mx : throw new InvalidOperationException(), UniqueLengths = lengths, Items = items, } diff --git a/MoreLinq.Test/ChooseTest.cs b/MoreLinq.Test/ChooseTest.cs index 95e2b3c8a..e1c335945 100644 --- a/MoreLinq.Test/ChooseTest.cs +++ b/MoreLinq.Test/ChooseTest.cs @@ -75,7 +75,7 @@ static class Option public void ThoseThatAreIntegers() { new int?[] { 0, 1, 2, null, 4, null, 6, null, null, 9 } - .Choose(e => e is int n ? Option.Some(n) : Option.None) + .Choose(e => e is {} n ? Option.Some(n) : Option.None) .AssertSequenceEqual(0, 1, 2, 4, 6, 9); } diff --git a/MoreLinq/AssertCount.cs b/MoreLinq/AssertCount.cs index 8296e166c..db4ff8e4f 100644 --- a/MoreLinq/AssertCount.cs +++ b/MoreLinq/AssertCount.cs @@ -89,7 +89,7 @@ static IEnumerable AssertCountImpl(IEnumerable source if (errorSelector == null) throw new ArgumentNullException(nameof(errorSelector)); return - source.TryGetCollectionCount() is int collectionCount + source.TryGetCollectionCount() is {} collectionCount ? collectionCount == count ? source : From(() => throw errorSelector(collectionCount.CompareTo(count), count)) diff --git a/MoreLinq/Backsert.cs b/MoreLinq/Backsert.cs index 928eef47a..1ac6a9d4c 100644 --- a/MoreLinq/Backsert.cs +++ b/MoreLinq/Backsert.cs @@ -72,7 +72,7 @@ public static IEnumerable Backsert(this IEnumerable first, IEnumerable< if (e.MoveNext()) { var (_, countdown) = e.Current; - if (countdown is int n && n != index - 1) + if (countdown is {} n && n != index - 1) throw new ArgumentOutOfRangeException(nameof(index), "Insertion index is greater than the length of the first sequence."); do diff --git a/MoreLinq/CountDown.cs b/MoreLinq/CountDown.cs index 94dd43675..f95985898 100644 --- a/MoreLinq/CountDown.cs +++ b/MoreLinq/CountDown.cs @@ -57,9 +57,9 @@ public static IEnumerable CountDown(this IEnumerable sou if (source == null) throw new ArgumentNullException(nameof(source)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return source.TryAsListLike() is IListLike listLike + return source.TryAsListLike() is {} listLike ? IterateList(listLike) - : source.TryGetCollectionCount() is int collectionCount + : source.TryGetCollectionCount() is {} collectionCount ? IterateCollection(collectionCount) : IterateSequence(); diff --git a/MoreLinq/CountMethods.cs b/MoreLinq/CountMethods.cs index b55ee8656..fd2cb640e 100644 --- a/MoreLinq/CountMethods.cs +++ b/MoreLinq/CountMethods.cs @@ -167,11 +167,11 @@ public static int CompareCount(this IEnumerable first, if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); - if (first.TryGetCollectionCount() is int firstCount) + if (first.TryGetCollectionCount() is {} firstCount) { return firstCount.CompareTo(second.TryGetCollectionCount() ?? second.CountUpTo(firstCount + 1)); } - else if (second.TryGetCollectionCount() is int secondCount) + else if (second.TryGetCollectionCount() is {} secondCount) { return first.CountUpTo(secondCount + 1).CompareTo(secondCount); } diff --git a/MoreLinq/EndsWith.cs b/MoreLinq/EndsWith.cs index ca1de4e66..2d9a2fcf5 100644 --- a/MoreLinq/EndsWith.cs +++ b/MoreLinq/EndsWith.cs @@ -74,8 +74,8 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, comparer ??= EqualityComparer.Default; List secondList; - return second.TryGetCollectionCount() is int secondCount - ? first.TryGetCollectionCount() is int firstCount && secondCount > firstCount + return second.TryGetCollectionCount() is {} secondCount + ? first.TryGetCollectionCount() is {} firstCount && secondCount > firstCount ? false : Impl(second, secondCount) : Impl(secondList = second.ToList(), secondList.Count); diff --git a/MoreLinq/Experimental/Await.cs b/MoreLinq/Experimental/Await.cs index 229fccbcb..834e7f5d3 100644 --- a/MoreLinq/Experimental/Await.cs +++ b/MoreLinq/Experimental/Await.cs @@ -636,7 +636,7 @@ void OnPendingCompleted() onEnd(); } - var concurrencyGate = maxConcurrency is int count + var concurrencyGate = maxConcurrency is {} count ? new ConcurrencyGate(count) : ConcurrencyGate.Unbounded; diff --git a/MoreLinq/Experimental/TrySingle.cs b/MoreLinq/Experimental/TrySingle.cs index 6aa591164..b88197ae5 100644 --- a/MoreLinq/Experimental/TrySingle.cs +++ b/MoreLinq/Experimental/TrySingle.cs @@ -115,7 +115,7 @@ public static TResult TrySingle(this IEnumerable so }; return resultSelector(one, item); } - case int _: + case {}: return resultSelector(many, default); default: { diff --git a/MoreLinq/FallbackIfEmpty.cs b/MoreLinq/FallbackIfEmpty.cs index 7d0c6915a..8675508c1 100644 --- a/MoreLinq/FallbackIfEmpty.cs +++ b/MoreLinq/FallbackIfEmpty.cs @@ -161,7 +161,7 @@ static IEnumerable FallbackIfEmptyImpl(IEnumerable source, int? count, T fallback1, T fallback2, T fallback3, T fallback4, IEnumerable fallback) { - return source.TryGetCollectionCount() is int collectionCount + return source.TryGetCollectionCount() is {} collectionCount ? collectionCount == 0 ? Fallback() : source : _(); diff --git a/MoreLinq/Flatten.cs b/MoreLinq/Flatten.cs index e98466c3e..ada470af3 100644 --- a/MoreLinq/Flatten.cs +++ b/MoreLinq/Flatten.cs @@ -110,7 +110,7 @@ public static IEnumerable Flatten(this IEnumerable source, Func PadStartImpl(IEnumerable source, int width, T padding, Func paddingSelector) { return - source.TryGetCollectionCount() is int collectionCount + source.TryGetCollectionCount() is {} collectionCount ? collectionCount >= width ? source : Enumerable.Range(0, width - collectionCount) diff --git a/MoreLinq/SkipLast.cs b/MoreLinq/SkipLast.cs index 6aebe4c3f..cfee629b3 100644 --- a/MoreLinq/SkipLast.cs +++ b/MoreLinq/SkipLast.cs @@ -41,7 +41,7 @@ public static IEnumerable SkipLast(this IEnumerable source, int count) return source; return - source.TryGetCollectionCount() is int collectionCount + source.TryGetCollectionCount() is {} collectionCount ? source.Take(collectionCount - count) : source.CountDown(count, (e, cd) => (Element: e, Countdown: cd )) .TakeWhile(e => e.Countdown == null) diff --git a/MoreLinq/StartsWith.cs b/MoreLinq/StartsWith.cs index 2bedebaf0..f6f298005 100644 --- a/MoreLinq/StartsWith.cs +++ b/MoreLinq/StartsWith.cs @@ -73,8 +73,8 @@ public static bool StartsWith(this IEnumerable first, IEnumerable secon if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); - if (first.TryGetCollectionCount() is int firstCount && - second.TryGetCollectionCount() is int secondCount && + if (first.TryGetCollectionCount() is {} firstCount && + second.TryGetCollectionCount() is {} secondCount && secondCount > firstCount) { return false; diff --git a/MoreLinq/TakeLast.cs b/MoreLinq/TakeLast.cs index 257c4d834..dba1d1ebb 100644 --- a/MoreLinq/TakeLast.cs +++ b/MoreLinq/TakeLast.cs @@ -54,7 +54,7 @@ public static IEnumerable TakeLast(this IEnumerable s return Enumerable.Empty(); return - source.TryGetCollectionCount() is int collectionCount + source.TryGetCollectionCount() is {} collectionCount ? source.Slice(Math.Max(0, collectionCount - count), int.MaxValue) : source.CountDown(count, (e, cd) => (Element: e, Countdown: cd)) .SkipWhile(e => e.Countdown == null)