From b23756e48fc8a7ed3f67ac046c3789e4ae7235f5 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 2 Dec 2022 10:09:25 +0100 Subject: [PATCH] feat: Enable Rules from 1826 to 1829 --- .editorconfig | 8 ++++++++ src/Avalonia.Controls/Selection/SelectionNodeBase.cs | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9ae52b8bbd..b39bbc2f71 100644 --- a/.editorconfig +++ b/.editorconfig @@ -145,6 +145,14 @@ dotnet_diagnostic.CA1820.severity = warning dotnet_diagnostic.CA1821.severity = warning # CA1825: Avoid zero-length array allocations dotnet_diagnostic.CA1825.severity = warning +# CA1826: Use property instead of Linq Enumerable method +dotnet_diagnostic.CA1826.severity = suggestion +# CA1827: Do not use Count/LongCount when Any can be used +dotnet_diagnostic.CA1827.severity = warning +# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used +dotnet_diagnostic.CA1828.severity = warning +# CA1829: Use Length/Count property instead of Enumerable.Count method +dotnet_diagnostic.CA1829.severity = warning #CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters dotnet_diagnostic.CA1847.severity = warning diff --git a/src/Avalonia.Controls/Selection/SelectionNodeBase.cs b/src/Avalonia.Controls/Selection/SelectionNodeBase.cs index 5994025d56..33a5525acc 100644 --- a/src/Avalonia.Controls/Selection/SelectionNodeBase.cs +++ b/src/Avalonia.Controls/Selection/SelectionNodeBase.cs @@ -290,12 +290,12 @@ namespace Avalonia.Controls.Selection // so bail. // // See unit test Handles_Selection_Made_In_CollectionChanged for more details. - if (ItemsView is object && + if (ItemsView is not null && RangesEnabled && Ranges.Count > 0 && e.Action == NotifyCollectionChangedAction.Add) { - var lastIndex = Ranges.Last().End; + var lastIndex = Ranges[Ranges.Count - 1].End; if (e.NewStartingIndex <= lastIndex) {