Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Aug 26, 2021
1 parent 4ec0dd7 commit f4de153
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 56 deletions.
11 changes: 3 additions & 8 deletions src/BasicSample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly: CLSCompliant(true)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
4 changes: 3 additions & 1 deletion src/BasicSample/DataItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BasicSample
#pragma warning disable CA5394 // Do not use insecure randomness

namespace BasicSample
{
using System;
using System.Windows;
Expand Down
2 changes: 1 addition & 1 deletion src/BasicSample/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.ObjectModel;
using System.Linq;

public class DataProvider
public static class DataProvider
{
/// <summary>
/// Provide a simple list of 100 random items.
Expand Down
7 changes: 4 additions & 3 deletions src/DataGridExtensions/ColumnStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ private static void Columns_CollectionChanged(DataGridColumnStyleCollection styl
if (args.Action != NotifyCollectionChangedAction.Add)
return;

var column = (DataGridColumn?)args.NewItems![0];
if (args.NewItems?[0] is not DataGridColumn column)
return;

ApplyStyle(styles, column);
}

private static void ApplyStyle(DataGridColumnStyleCollection styles, DependencyObject? column)
private static void ApplyStyle(DataGridColumnStyleCollection styles, DependencyObject column)
{
var columnType = column?.GetType();
var columnType = column.GetType();

var style = styles.FirstOrDefault(s => s.ColumnType == columnType);
if (style == null)
Expand Down
4 changes: 2 additions & 2 deletions src/DataGridExtensions/DataGridFilterColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ internal static bool Matches(this DataGridColumn? column, DataGrid dataGrid, obj
/// Examines the property path and returns the objects value for this column.
/// Filtering is applied on the SortMemberPath, this is the path used to create the binding.
/// </summary>
internal static object? GetCellContentData(this DataGridColumn? column, object? item)
internal static object? GetCellContentData(this DataGridColumn column, object? item)
{
var propertyPath = column?.SortMemberPath;
var propertyPath = column.SortMemberPath;
if (item == null || string.IsNullOrEmpty(propertyPath))
{
return null;
Expand Down
17 changes: 5 additions & 12 deletions src/DataGridExtensions/ListBoxSelectAllBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,11 @@ private void ListBox_SelectionChanged(object? sender, EventArgs? e)
{
_isListBoxUpdating = true;

if (listBox.Items.Count == listBox.SelectedItems.Count)
{
AreAllFilesSelected = true;
}
else if (listBox.SelectedItems.Count == 0)
{
AreAllFilesSelected = false;
}
else
{
AreAllFilesSelected = null;
}
AreAllFilesSelected = listBox.Items.Count == listBox.SelectedItems.Count
? true
: listBox.SelectedItems.Count == 0
? false
: null;
}
finally
{
Expand Down
5 changes: 5 additions & 0 deletions src/DataGridExtensionsSample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;
using System.Windows;

[assembly: CLSCompliant(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ private void Filter_Changed()
Maximum = filter.Max;
}

public class ContentFilter : IContentFilter
{
public ContentFilter(double min, double max)
{
Min = min;
Max = max;
}
}

public double Min { get; }
public class ContentFilter : IContentFilter
{
public ContentFilter(double min, double max)
{
Min = min;
Max = max;
}

public double Max { get; }
public double Min { get; }

public bool IsMatch(object? value)
{
if (value == null)
return false;
public double Max { get; }

if (!double.TryParse(value.ToString(), out var number))
{
return false;
}
public bool IsMatch(object? value)
{
if (value == null)
return false;

return (number >= Min) && (number <= Max);
if (!double.TryParse(value.ToString(), out var number))
{
return false;
}
}

return (number >= Min) && (number <= Max);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ private void Filter_Changed(object newValue)
textBox.Text = (newValue as ContentFilter)?.Value ?? string.Empty;
}

class ContentFilter : IContentFilter
private class ContentFilter : IContentFilter
{
readonly int _threshold;
private readonly int _threshold;

public ContentFilter(int threshold)
{
Expand Down
4 changes: 3 additions & 1 deletion src/DataGridExtensionsSample/Infrastructure/DataItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DataGridExtensionsSample.Infrastructure
#pragma warning disable CA5394 // Do not use insecure randomness

namespace DataGridExtensionsSample.Infrastructure
{
using System;
using System.Windows;
Expand Down
2 changes: 1 addition & 1 deletion src/DataGridExtensionsSample/Infrastructure/RegionId.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DataGridExtensionsSample.Infrastructure
{
class RegionId
internal class RegionId
{
public const string Shell = "Shell";
public const string Main = "Main";
Expand Down
4 changes: 2 additions & 2 deletions src/DataGridExtensionsSample/Views/BasicView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public BasicView()
DataGrid.GetFilter().Filtering += DataGrid_Filtering;
}

void DataGrid_Filtering(object? sender, DataGridFilteringEventArgs e)
private void DataGrid_Filtering(object? sender, DataGridFilteringEventArgs e)
{
// Here we could prepare some data or even cancel the filtering process.

Dispatcher.BeginInvoke(new Action(DataGrid_Filtered));
}

void DataGrid_Filtered()
private void DataGrid_Filtered()
{
// Here we could show some information about the result of the filtering.

Expand Down
2 changes: 1 addition & 1 deletion src/DataGridExtensionsSample/Views/Customized1ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[VisualCompositionExport(RegionId.Main, Sequence = 2)]
[DisplayName("Customized 1")]
class Customized1ViewModel : ObservableObject
internal class Customized1ViewModel : ObservableObject
{
public Customized1ViewModel(DataProvider dataProvider)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DataGridExtensionsSample/Views/Customized2ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
using TomsToolbox.Wpf;
using TomsToolbox.Wpf.Composition.AttributedModel;

using static DataGridExtensionsSample.Controls.FilterWithPopupControl;

[VisualCompositionExport(RegionId.Main, Sequence = 3)]
[DisplayName("Customized 2")]
internal class Customized2ViewModel : ObservableObject
Expand All @@ -40,7 +38,9 @@ public Customized2ViewModel(DataProvider dataProvider)

public DataGridFilterColumnControl? Column5FilterColumnControl { get; set; }

#pragma warning disable CA1307 // Specify StringComparison for clarity => only supported in net5.0!
public Predicate<object> GlobalFilter { get; } = item => (item as DataItem)?.Column1?.Contains('7') ?? false;
#pragma warning restore CA1307 // Specify StringComparison for clarity

public ICommand ClearIpsumCommand => new DelegateCommand(ClearIpsum);

Expand Down
2 changes: 1 addition & 1 deletion src/DataGridExtensionsSample/Views/GroupingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[VisualCompositionExport(RegionId.Main, Sequence = 5)]
[DisplayName("Grouping")]
class GroupingViewModel : ObservableObject
internal class GroupingViewModel : ObservableObject
{
public GroupingViewModel(DataProvider dataProvider)
{
Expand Down

0 comments on commit f4de153

Please sign in to comment.