From 1961f4b4ac2cf9c761a363f3305279284b2f527f Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sat, 5 Oct 2024 00:05:13 -0500 Subject: [PATCH 1/5] suppress warning --- Maui.DataGrid/DataGrid.xaml.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maui.DataGrid/DataGrid.xaml.cs b/Maui.DataGrid/DataGrid.xaml.cs index ae44c5f..dc2b8d4 100644 --- a/Maui.DataGrid/DataGrid.xaml.cs +++ b/Maui.DataGrid/DataGrid.xaml.cs @@ -1495,11 +1495,13 @@ private bool FilterItem(object item, DataGridColumn column) return result == true; } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { Debug.WriteLine(ex); return false; } +#pragma warning restore CA1031 // Do not catch general exception types } private IEnumerable GetPaginatedItems(IEnumerable unpaginatedItems) From 7d5bfb7eba7ec2c958879ccf467b9ee369672bd2 Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sat, 5 Oct 2024 00:12:58 -0500 Subject: [PATCH 2/5] remove regions --- Maui.DataGrid/DataGrid.xaml.cs | 94 +++++++++++----------------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/Maui.DataGrid/DataGrid.xaml.cs b/Maui.DataGrid/DataGrid.xaml.cs index dc2b8d4..d193bc4 100644 --- a/Maui.DataGrid/DataGrid.xaml.cs +++ b/Maui.DataGrid/DataGrid.xaml.cs @@ -21,8 +21,6 @@ namespace Maui.DataGrid; [XamlCompilation(XamlCompilationOptions.Compile)] public partial class DataGrid { - #region Bindable properties - /// /// Gets or sets the color of the active row. /// @@ -637,10 +635,6 @@ public partial class DataGrid } }); - #endregion Bindable properties - - #region Fields - private static readonly SortedSet DefaultPageSizeSet = [5, 10, 50, 100, 200, 1000]; private static readonly IList DefaultPageSizeList = [.. DefaultPageSizeSet]; @@ -659,10 +653,6 @@ public partial class DataGrid [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] private Type? _cachedType; - #endregion Fields - - #region ctor - /// /// Initializes a new instance of the class. /// @@ -680,10 +670,6 @@ public DataGrid() } } - #endregion ctor - - #region Events - /// /// Occurs when an item is selected in the DataGrid. /// @@ -720,10 +706,6 @@ internal event EventHandler RowsTextColorPaletteChanged remove => _rowsTextColorPaletteChangedEventManager.RemoveEventHandler(value); } - #endregion Events - - #region Properties - #pragma warning disable CA2227 // Collection properties should be read only /// @@ -1155,10 +1137,6 @@ private set internal ObservableRangeCollection InternalItems { get; } = []; - #endregion Properties - - #region Methods - /// /// Scrolls to the row. /// @@ -1182,9 +1160,36 @@ internal void Initialize() } } - #endregion Methods + internal void SortFilterAndPaginate(SortData? sortData = null) + { + if (ItemsSource is null) + { + return; + } + + lock (_sortAndPaginateLock) + { + sortData ??= SortedColumnIndex; + + var originalItems = ItemsSource as IList ?? ItemsSource.Cast().ToList(); + + PageCount = (int)Math.Ceiling(originalItems.Count / (double)PageSize); - #region UI Methods + if (originalItems.Count == 0) + { + InternalItems.Clear(); + return; + } + + var filteredItems = CanFilter() ? GetFilteredItems(originalItems) : originalItems; + + var sortedItems = CanSort(sortData) ? GetSortedItems(filteredItems, sortData!) : filteredItems; + + var paginatedItems = PaginationEnabled ? GetPaginatedItems(sortedItems) : sortedItems; + + InternalItems.ReplaceRange(paginatedItems); + } + } /// protected override void OnParentSet() @@ -1313,10 +1318,6 @@ private ICollection GetInternalItems(int lookupCount = 1) return new(newSortedColumnIndex, SortedColumnIndex.Order); } - #endregion UI Methods - - #region Sorting methods - private bool CanFilter() => FilteringEnabled && Columns.Any(c => c.FilteringEnabled); private bool CanSort(SortData? sortData) @@ -1413,41 +1414,6 @@ private IEnumerable GetSortedItems(IList unsortedItems, SortData return items; } - #endregion Sorting methods - - #region Pagination methods - - internal void SortFilterAndPaginate(SortData? sortData = null) - { - if (ItemsSource is null) - { - return; - } - - lock (_sortAndPaginateLock) - { - sortData ??= SortedColumnIndex; - - var originalItems = ItemsSource as IList ?? ItemsSource.Cast().ToList(); - - PageCount = (int)Math.Ceiling(originalItems.Count / (double)PageSize); - - if (originalItems.Count == 0) - { - InternalItems.Clear(); - return; - } - - var filteredItems = CanFilter() ? GetFilteredItems(originalItems) : originalItems; - - var sortedItems = CanSort(sortData) ? GetSortedItems(filteredItems, sortData!) : filteredItems; - - var paginatedItems = PaginationEnabled ? GetPaginatedItems(sortedItems) : sortedItems; - - InternalItems.ReplaceRange(paginatedItems); - } - } - private List GetFilteredItems(IList originalItems) { var filteredItems = originalItems.AsEnumerable(); @@ -1528,6 +1494,4 @@ private void UpdatePageSizeList() OnPropertyChanged(nameof(PageSize)); } } - - #endregion Pagination methods } From 9a166e4ba9c7f2ede4b442bc1899b42ca4502e29 Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sat, 5 Oct 2024 00:13:20 -0500 Subject: [PATCH 3/5] remove pragma --- Maui.DataGrid/DataGrid.xaml.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Maui.DataGrid/DataGrid.xaml.cs b/Maui.DataGrid/DataGrid.xaml.cs index d193bc4..515aa08 100644 --- a/Maui.DataGrid/DataGrid.xaml.cs +++ b/Maui.DataGrid/DataGrid.xaml.cs @@ -1127,8 +1127,6 @@ private set } } -#pragma warning restore CA2227 // Collection properties should be read only - internal Style DefaultHeaderLabelStyle { get; } internal Style DefaultHeaderFilterStyle { get; } From 9576d8a8538308b921b88f5389efc9e5da15079b Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sat, 5 Oct 2024 11:20:11 -0500 Subject: [PATCH 4/5] treat warnings as errors --- Directory.Build.props | 1 + Maui.DataGrid.Sample/App.xaml.cs | 2 ++ Maui.DataGrid.Sample/Converters/StreakToColorConverter.cs | 2 ++ Maui.DataGrid/Collections/ObservableRangeCollection.cs | 2 ++ Maui.DataGrid/DataGrid.xaml.cs | 2 ++ Maui.DataGrid/DataGridHeaderRow.cs | 2 ++ Maui.DataGrid/DataGridRow.cs | 2 ++ Maui.DataGrid/Maui.DataGrid.csproj | 1 + 8 files changed, 14 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index be9555f..83ad359 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,6 +11,7 @@ 9999 latest-all true + true true true true diff --git a/Maui.DataGrid.Sample/App.xaml.cs b/Maui.DataGrid.Sample/App.xaml.cs index b9719ba..4df1823 100644 --- a/Maui.DataGrid.Sample/App.xaml.cs +++ b/Maui.DataGrid.Sample/App.xaml.cs @@ -1,5 +1,7 @@ namespace Maui.DataGrid.Sample; +#pragma warning disable CA1724 + /// /// Codebehind for the App. /// diff --git a/Maui.DataGrid.Sample/Converters/StreakToColorConverter.cs b/Maui.DataGrid.Sample/Converters/StreakToColorConverter.cs index f6f6a5a..6b570ee 100644 --- a/Maui.DataGrid.Sample/Converters/StreakToColorConverter.cs +++ b/Maui.DataGrid.Sample/Converters/StreakToColorConverter.cs @@ -1,8 +1,10 @@ namespace Maui.DataGrid.Sample.Converters; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using Maui.DataGrid.Sample.Models; +[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated via XAML")] internal sealed class StreakToColorConverter : IValueConverter { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) diff --git a/Maui.DataGrid/Collections/ObservableRangeCollection.cs b/Maui.DataGrid/Collections/ObservableRangeCollection.cs index 702348b..6165cd6 100644 --- a/Maui.DataGrid/Collections/ObservableRangeCollection.cs +++ b/Maui.DataGrid/Collections/ObservableRangeCollection.cs @@ -15,11 +15,13 @@ namespace Maui.DataGrid.Collections; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; /// /// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed. /// /// The object type of elements in the collection. +[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated via collection expression")] internal sealed class ObservableRangeCollection : ObservableCollection { /// diff --git a/Maui.DataGrid/DataGrid.xaml.cs b/Maui.DataGrid/DataGrid.xaml.cs index 515aa08..810301c 100644 --- a/Maui.DataGrid/DataGrid.xaml.cs +++ b/Maui.DataGrid/DataGrid.xaml.cs @@ -15,6 +15,8 @@ namespace Maui.DataGrid; using Microsoft.Maui.Controls.Shapes; using Font = Microsoft.Maui.Font; +#pragma warning disable CA1724 + /// /// DataGrid component for .NET MAUI. /// diff --git a/Maui.DataGrid/DataGridHeaderRow.cs b/Maui.DataGrid/DataGridHeaderRow.cs index fc40d7b..18c109a 100644 --- a/Maui.DataGrid/DataGridHeaderRow.cs +++ b/Maui.DataGrid/DataGridHeaderRow.cs @@ -1,8 +1,10 @@ namespace Maui.DataGrid; +using System.Diagnostics.CodeAnalysis; using Maui.DataGrid.Extensions; using Microsoft.Maui.Controls; +[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated via XAML")] internal sealed class DataGridHeaderRow : Grid { #region Bindable Properties diff --git a/Maui.DataGrid/DataGridRow.cs b/Maui.DataGrid/DataGridRow.cs index c3b8e3b..9ff45ac 100644 --- a/Maui.DataGrid/DataGridRow.cs +++ b/Maui.DataGrid/DataGridRow.cs @@ -1,8 +1,10 @@ namespace Maui.DataGrid; +using System.Diagnostics.CodeAnalysis; using Maui.DataGrid.Extensions; using Microsoft.Maui.Controls; +[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated via XAML")] internal sealed class DataGridRow : Grid { #region Bindable Properties diff --git a/Maui.DataGrid/Maui.DataGrid.csproj b/Maui.DataGrid/Maui.DataGrid.csproj index 58fb90b..a9e94dd 100644 --- a/Maui.DataGrid/Maui.DataGrid.csproj +++ b/Maui.DataGrid/Maui.DataGrid.csproj @@ -40,6 +40,7 @@ \ + all From bda06bc3a670757bcae25aac5b17c3a647ef18b2 Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sun, 6 Oct 2024 23:58:09 -0500 Subject: [PATCH 5/5] remove padding --- Maui.DataGrid/DataGridHeaderRow.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Maui.DataGrid/DataGridHeaderRow.cs b/Maui.DataGrid/DataGridHeaderRow.cs index 18c109a..6743518 100644 --- a/Maui.DataGrid/DataGridHeaderRow.cs +++ b/Maui.DataGrid/DataGridHeaderRow.cs @@ -28,8 +28,6 @@ internal sealed class DataGridHeaderRow : Grid new() { Width = new(1, GridUnitType.Auto) }, ]; - private readonly Thickness _headerCellPadding = new(0, 0, 4, 0); - private readonly Command _sortCommand = new(OnSort, CanSort); #endregion Fields @@ -197,7 +195,6 @@ private DataGridCell CreateHeaderCell(DataGridColumn column) var cellContent = new Grid { - Padding = _headerCellPadding, ColumnDefinitions = _headerColumnDefinitions, RowDefinitions = _headerRowDefinitions, };