Skip to content

Commit be9dadc

Browse files
committed
Fix some warnings
1 parent a92137c commit be9dadc

9 files changed

Lines changed: 58 additions & 43 deletions

File tree

src/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ dotnet_diagnostic.IDE0011.severity = none
2828

2929
# IDE0065: Misplaced using directive
3030
dotnet_diagnostic.IDE0065.severity = none
31+
32+
# IDE0078: Use pattern matching
33+
dotnet_diagnostic.IDE0078.severity = silent
34+
35+
# IDE0083: Use pattern matching
36+
dotnet_diagnostic.IDE0083.severity = silent
37+
38+
# IDE0010: Add missing cases
39+
dotnet_diagnostic.IDE0010.severity = silent

src/DataGridExtensions/Behaviors/ExtendedStarSizeBehavior.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ExtendedStarSizeBehavior : Behavior<DataGrid>
3939
public static readonly ResourceKey ColumnHeaderGripperToolTipStyleKey = new ComponentResourceKey(typeof(ExtendedStarSizeBehavior), "ColumnHeaderGripperToolTipStyle");
4040

4141
/// <summary>
42-
/// Initializes a new instance of the <see cref="DataGridExtensions.Behaviors.ExtendedStarSizeBehavior" /> class.
42+
/// Initializes a new instance of the <see cref="ExtendedStarSizeBehavior" /> class.
4343
/// </summary>
4444
public ExtendedStarSizeBehavior()
4545
{
@@ -118,9 +118,11 @@ private void DataGrid_Loaded(DataGrid dataGrid)
118118
InjectColumnHeaderStyle(dataGrid);
119119
}
120120

121-
private void DataGrid_Unloaded(object sender, RoutedEventArgs e)
121+
private void DataGrid_Unloaded(object? sender, RoutedEventArgs e)
122122
{
123-
var dataGrid = (DataGrid)sender;
123+
var dataGrid = (DataGrid?)sender;
124+
if (dataGrid == null)
125+
return;
124126

125127
var scrollViewer = _scrollViewer;
126128
if (scrollViewer == null)
@@ -142,7 +144,7 @@ private void DataGrid_ColumnDisplayIndexChanged(object? sender, DataGridColumnEv
142144
_updateColumnGripperToolTipVisibilityThrottle.Tick();
143145
}
144146

145-
private void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
147+
private void Columns_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
146148
{
147149
var dataGrid = AssociatedObject;
148150
if (dataGrid == null)
@@ -213,7 +215,7 @@ private void UpdateColumnWidths(DataGrid dataGrid, DataGridColumn? modifiedColum
213215
var dataGridColumns = dataGrid.Columns
214216
.OrderBy(c => c.DisplayIndex)
215217
.Skip(dataGrid.FrozenColumnCount)
216-
.Where(c => (c.Visibility == Visibility.Visible))
218+
.Where(c => c.Visibility == Visibility.Visible)
217219
.ToArray();
218220

219221
_columnsAreFitWithinViewPort = !ApplyStarSize(dataGridColumns, modifiedColumn) && DistributeAvailableSize(dataGrid, dataGridColumns, modifiedColumn, updateMode);
@@ -250,8 +252,15 @@ private bool DistributeAvailableSize(DataGrid dataGrid, DataGridColumn[] dataGri
250252

251253
var startColumnIndex = modifiedColumn?.DisplayIndex ?? 0;
252254

253-
bool IsFixedColumn(DataGridColumn c) => (GetStarSize(c) <= double.Epsilon) || (c.DisplayIndex <= startColumnIndex);
254-
bool IsVariableColumn(DataGridColumn c) => !IsFixedColumn(c);
255+
bool IsFixedColumn(DataGridColumn c)
256+
{
257+
return (GetStarSize(c) <= double.Epsilon) || (c.DisplayIndex <= startColumnIndex);
258+
}
259+
260+
bool IsVariableColumn(DataGridColumn c)
261+
{
262+
return !IsFixedColumn(c);
263+
}
255264

256265
var fixedColumnsWidth = dataGridColumns
257266
.Where(IsFixedColumn)

src/DataGridExtensions/ColumnStyles.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ private static void Columns_CollectionChanged(DataGridColumnStyleCollection styl
6060
if (args.Action != NotifyCollectionChangedAction.Add)
6161
return;
6262

63-
var column = (DataGridColumn)args.NewItems[0];
63+
var column = (DataGridColumn?)args.NewItems![0];
6464

6565
ApplyStyle(styles, column);
6666
}
6767

68-
private static void ApplyStyle(DataGridColumnStyleCollection styles, DependencyObject column)
68+
private static void ApplyStyle(DataGridColumnStyleCollection styles, DependencyObject? column)
6969
{
70-
var style = styles.FirstOrDefault(s => s.ColumnType == column.GetType());
70+
var columnType = column?.GetType();
7171

72+
var style = styles.FirstOrDefault(s => s.ColumnType == columnType);
7273
if (style == null)
7374
return;
7475

src/DataGridExtensions/DataGridEventsProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@ public DataGridEventsProvider(DataGrid dataGrid)
3535

3636
public event EventHandler<DataGridColumnEventArgs>? ColumnSortDirectionChanged;
3737

38-
private void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
38+
private void Columns_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
3939
{
4040
switch (e.Action)
4141
{
4242
case NotifyCollectionChangedAction.Add:
43-
foreach (var column in e.NewItems.OfType<DataGridColumn>())
43+
foreach (var column in e.NewItems!.OfType<DataGridColumn>())
4444
{
4545
AddEventHandlers(column);
4646
}
4747
break;
4848

4949
case NotifyCollectionChangedAction.Remove:
50-
foreach (var column in e.OldItems.OfType<DataGridColumn>())
50+
foreach (var column in e.OldItems!.OfType<DataGridColumn>())
5151
{
5252
RemoveEventHandlers(column);
5353
}
5454
break;
5555

5656
case NotifyCollectionChangedAction.Replace:
57-
foreach (var column in e.OldItems.OfType<DataGridColumn>())
57+
foreach (var column in e.OldItems!.OfType<DataGridColumn>())
5858
{
5959
RemoveEventHandlers(column);
6060
}
61-
foreach (var column in e.NewItems.OfType<DataGridColumn>())
61+
foreach (var column in e.NewItems!.OfType<DataGridColumn>())
6262
{
6363
AddEventHandlers(column);
6464
}

src/DataGridExtensions/DataGridFilterColumnControl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ internal bool Matches(DataGrid dataGrid, object? item)
362362
return property.GetValue(item);
363363
}
364364
}
365+
#pragma warning disable CA1031 // Do not catch general exception types
365366
catch
367+
#pragma warning restore CA1031 // Do not catch general exception types
366368
{
367369
// not a plain property, fall-back to binding...
368370
}

src/DataGridExtensions/DataGridFilterHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void DataGrid_CanSelectAll(object? sender, CanExecuteRoutedEventArgs e)
188188
e.CanExecute = DataGrid.CanSelectAll() || (DataGrid.Items.Count == 0);
189189
}
190190

191-
private void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
191+
private void Columns_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
192192
{
193193
if (e.Action == NotifyCollectionChangedAction.Reset)
194194
{

src/DataGridExtensions/MultipleChoiceFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected virtual void OnSourceValuesChanged(IEnumerable<string?>? newValue)
143143
values.SynchronizeWith(newValue.ExceptNullItems().ToArray());
144144
}
145145

146-
private void ListBox_ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
146+
private void ListBox_ItemsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
147147
{
148148
var filter = Filter;
149149

src/DataGridExtensionsSample/Controls/FilterWithPopupControl.xaml.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace DataGridExtensionsSample.Controls
22
{
3-
using System.Windows;
4-
using DataGridExtensions;
3+
using System.Windows;
4+
using DataGridExtensions;
55

6-
/// <summary>
7-
/// Interaction logic for FilterWithPopupControl.xaml
8-
/// </summary>
9-
public partial class FilterWithPopupControl
6+
/// <summary>
7+
/// Interaction logic for FilterWithPopupControl.xaml
8+
/// </summary>
9+
public partial class FilterWithPopupControl
1010
{
1111
public FilterWithPopupControl()
1212
{
@@ -56,11 +56,7 @@ public bool IsPopupVisible
5656
/// Identifies the IsPopupVisible dependency property
5757
/// </summary>
5858
public static readonly DependencyProperty IsPopupVisibleProperty =
59-
DependencyProperty.Register("IsPopupVisible", typeof(bool), typeof(FilterWithPopupControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, e) => ((FilterWithPopupControl)sender).IsPopupVisible_Changed()));
60-
61-
private void IsPopupVisible_Changed()
62-
{
63-
}
59+
DependencyProperty.Register("IsPopupVisible", typeof(bool), typeof(FilterWithPopupControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
6460

6561
private void Range_Changed()
6662
{
@@ -90,18 +86,15 @@ private void Filter_Changed()
9086

9187
public class ContentFilter : IContentFilter
9288
{
93-
private readonly double _min;
94-
private readonly double _max;
95-
9689
public ContentFilter(double min, double max)
9790
{
98-
_min = min;
99-
_max = max;
91+
Min = min;
92+
Max = max;
10093
}
10194

102-
public double Min => _min;
95+
public double Min { get; }
10396

104-
public double Max => _max;
97+
public double Max { get; }
10598

10699
public bool IsMatch(object? value)
107100
{
@@ -113,7 +106,7 @@ public bool IsMatch(object? value)
113106
return false;
114107
}
115108

116-
return (number >= _min) && (number <= _max);
109+
return (number >= Min) && (number <= Max);
117110
}
118111
}
119112

src/DataGridExtensionsSample/Views/Customized2ViewModel.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
using System;
44
using System.Collections.Generic;
55
using System.ComponentModel;
6-
using System.Windows.Controls;
76
using System.Windows.Input;
8-
using System.Windows.Media;
7+
98
using DataGridExtensions;
9+
1010
using DataGridExtensionsSample.Controls;
1111
using DataGridExtensionsSample.Infrastructure;
1212

1313
using TomsToolbox.Essentials;
1414
using TomsToolbox.Wpf;
1515
using TomsToolbox.Wpf.Composition.AttributedModel;
16+
1617
using static DataGridExtensionsSample.Controls.FilterWithPopupControl;
1718

1819
[VisualCompositionExport(RegionId.Main, Sequence = 3)]
1920
[DisplayName("Customized 2")]
20-
class Customized2ViewModel : ObservableObject
21+
internal class Customized2ViewModel : ObservableObject
2122
{
2223
public Customized2ViewModel(DataProvider dataProvider)
2324
{
@@ -28,13 +29,13 @@ public Customized2ViewModel(DataProvider dataProvider)
2829

2930
public object Column2Filter { get; set; } = "A";
3031

31-
public object Column5Filter { get; set; }
32+
public object? Column5Filter { get; set; }
3233

3334
public object ColumnTextWithPrefilterFilter { get; set; } = new MultipleChoiceContentFilter(new List<string> { "amet" });
3435

3536
public bool Column5PopupVisible { get; set; }
3637

37-
public DataGridFilterColumnControl Column5FilterColumnControl { get; set; }
38+
public DataGridFilterColumnControl? Column5FilterColumnControl { get; set; }
3839

3940
public Predicate<object> GlobalFilter { get; } = item => (item as DataItem)?.Column1?.Contains("7") ?? false;
4041

@@ -50,7 +51,7 @@ private void ClearIpsum()
5051
private void OpenAndPopulateAFilter()
5152
{
5253
Column5Filter = new ContentFilter(0.5d, 1d);
53-
if (Column5FilterColumnControl.FilterControl is FilterWithPopupControl filterWithPopupControl)
54+
if (Column5FilterColumnControl?.FilterControl is FilterWithPopupControl filterWithPopupControl)
5455
{
5556
filterWithPopupControl.IsPopupVisible = true;
5657
}
@@ -60,7 +61,7 @@ private void OpenAndPopulateAFilter()
6061

6162
private void ProgrammaticAccessToFilterControl()
6263
{
63-
if (Column5FilterColumnControl.FilterControl is FilterWithPopupControl filterWithPopupControl)
64+
if (Column5FilterColumnControl?.FilterControl is FilterWithPopupControl filterWithPopupControl)
6465
{
6566
filterWithPopupControl.Caption = "New Popup Caption:";
6667
filterWithPopupControl.IsPopupVisible = true;

0 commit comments

Comments
 (0)