Skip to content

Analyzer Warning Mitigation #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
edbcb95
Fix null analyzer complaints: CS8602, CS8618, CS8603, CS8622, IDE0031
koal44 Mar 29, 2024
ca56561
Hide warnings related to IDE0008 related to using `var` keyword
koal44 Mar 29, 2024
750a6e8
Removed Coersion logic from IconSourceElementConverter, and placed in…
koal44 Mar 29, 2024
c17bc39
Cleaning single-line warnings: SA1005
koal44 Mar 29, 2024
8d46fb1
Fix missing braces or single-lined braces
koal44 Mar 29, 2024
211b299
Fix warnings on registered dependency properties
koal44 Mar 29, 2024
3388a5e
Fix documentation warnings
koal44 Mar 30, 2024
5f677e1
Fix warnings about using language keywords
koal44 Mar 30, 2024
87d68c5
Fix warnings where attributes are on a single line SA1133
koal44 Mar 30, 2024
7247479
When setting DPs, favor SetCurrentValue over the CLR setter. WPF0041
koal44 Mar 30, 2024
7f714f2
Remove unnecessary things (parenthesis, assignments, etc). SA1119, ID…
koal44 Mar 30, 2024
1f4ad89
Fix order of operation warnings
koal44 Mar 30, 2024
ef55428
Do not use regions SA1124. Clean VirtualizingPanelBase of warnings
koal44 Mar 30, 2024
d50f6aa
Turn protected control fields into protected properties. fix some doc…
koal44 Mar 30, 2024
b4d9616
Cleanup warnings in Interop classes and suppress warnings related to …
koal44 Mar 30, 2024
569bd70
Continue cleaning up warnings in Wpf.Ui
koal44 Mar 31, 2024
704aa7e
Edit .editorconfig to suppress warnings related to valueconverters
koal44 Mar 31, 2024
d5fed43
Cleanup warning related to 'var'
koal44 Mar 31, 2024
40116b1
Fix warnings
koal44 Apr 1, 2024
6459d9c
Split ContextMenu style from its loader dictionary
koal44 Apr 1, 2024
6f1612c
Resolve "expression value is never used" IDE0058 warnings
koal44 Apr 1, 2024
d0f8ed1
Fix warnings related to collection initialization.
koal44 Apr 1, 2024
7041e7b
Remove unused suppressions
koal44 Apr 1, 2024
d345236
Supress IDE0290 (Use primary constructor). Just didn't seem necessary.
koal44 Apr 1, 2024
fbc7a37
IDE0009 should be configured through dotnet_styles
koal44 Apr 1, 2024
a74dd3e
Separate out the loader component from the Menu.xaml style.
koal44 Apr 1, 2024
2df052d
Fix warnings on NavigationView.NavigationParent attached property
koal44 Apr 2, 2024
977ccf7
Fix warnings related to setting refernce types as default values. for…
koal44 Apr 2, 2024
1bb3092
Fix warnings
koal44 Apr 4, 2024
5b57ba0
Fix regression error where the ContentDialog wouldn't appear and chan…
koal44 Apr 6, 2024
51a9e0d
Remove obsolete forceBacground parameters. Breaking changes
koal44 Apr 6, 2024
a8f9325
Remove redundant #if DEBUG directives around Debug.WriteLine calls
koal44 Apr 6, 2024
ac0ccf4
Fix some analyzer warnings
koal44 Apr 6, 2024
659760f
Merge branch 'development' into clean/deal-with-warnings
koal44 Apr 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ file_header_template = This Source Code Form is subject to the terms of the MIT
#### .NET Coding Conventions ####

# this. and Me. preferences
dotnet_style_qualification_for_event = false:warning
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
Expand Down Expand Up @@ -95,8 +95,8 @@ dotnet_style_readonly_field = true:warning

# var preferences
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = false:none

# Expression-bodied members
csharp_style_expression_bodied_accessors = false:silent
Expand Down Expand Up @@ -388,7 +388,7 @@ dotnet_diagnostic.SA1633.severity = none
dotnet_diagnostic.SA1634.severity = none
dotnet_diagnostic.SA1652.severity = none

dotnet_diagnostic.IDE0009.severity = none


# Additional Stylecop Analyzers
dotnet_diagnostic.SA1111.severity = none
Expand All @@ -397,3 +397,19 @@ dotnet_diagnostic.SA1204.severity = none
dotnet_diagnostic.SA1208.severity = none
dotnet_diagnostic.SA1518.severity = none
dotnet_diagnostic.SA1615.severity = none
dotnet_diagnostic.SA1502.severity = none
dotnet_diagnostic.SA1010.severity = none # Opening square brackets should not be preceded by a space
# conflicts with collection expressions and IDE0028

# Suppress some ValueConverter warnings
dotnet_diagnostic.WPF0073.severity = none # Add ValueConversion attribute (unknown types)
dotnet_diagnostic.WPF0071.severity = none # Add ValueConversion attribute
dotnet_diagnostic.WPF0070.severity = none # Add default field to converter

# Suppress some IDE warnings
dotnet_diagnostic.IDE0290.severity = none # Use primary constructor
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member
# 15000+ warnings in the solution
dotnet_diagnostic.CA1510.severity = none # Use ArgumentNullException throw helper
# doesn't work with older versions of .NET

4 changes: 4 additions & 0 deletions src/Wpf.Ui.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Diagnostics;

public static class Program
{
[STAThread]
public static void Main(string[] args)
{
Debug.WriteLine("Args: " + string.Join(", ", args));

if (Application.Current is null)
{
Console.WriteLine($"Application.Current is null.");
Expand Down
12 changes: 8 additions & 4 deletions src/Wpf.Ui.Demo.Console/Utilities/ThemeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ public static void ApplyTheme(this FrameworkElement frameworkElement)
{
ApplicationThemeManager.Apply(frameworkElement);

ThemeChangedEvent themeChanged = (sender, args) =>
void themeChanged(ApplicationTheme sender, Color args)
{
ApplicationThemeManager.Apply(frameworkElement);
if (frameworkElement is Window window)
{
if (window != UiApplication.Current.MainWindow)
{
WindowBackgroundManager.UpdateBackground(
window,
sender,
Wpf.Ui.Controls.WindowBackdropType.None,
true
Wpf.Ui.Controls.WindowBackdropType.None
);
}
}
};
}

if (frameworkElement.IsLoaded)
{
ApplicationThemeManager.Changed += themeChanged;
}

frameworkElement.Loaded += (s, e) =>
{
ApplicationThemeManager.Changed += themeChanged;
Expand Down Expand Up @@ -85,6 +87,7 @@ public static void ChangeTheme()
ApplicationThemeManager.Apply(applicationTheme, updateAccent: false);
}

/*
/// <summary>
/// Applies Resources in the <paramref name="frameworkElement"/>.
/// </summary>
Expand Down Expand Up @@ -128,4 +131,5 @@ private static void Apply(FrameworkElement frameworkElement)
frameworkElement.Resources[resource.Key] = resource.Value;
}
}
*/
}
4 changes: 3 additions & 1 deletion src/Wpf.Ui.Demo.Console/Views/Pages/DataPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Wpf.Ui.Demo.Console.Views.Pages;
/// </summary>
public partial class DataPage
{
public ObservableCollection<DataColor> ColorsCollection = new();
public ObservableCollection<DataColor> ColorsCollection = [];

public DataPage()
{
Expand All @@ -30,6 +30,7 @@ private void InitializeData()
var random = new Random();

for (int i = 0; i < 8192; i++)
{
ColorsCollection.Add(
new DataColor
{
Expand All @@ -43,5 +44,6 @@ private void InitializeData()
)
}
);
}
}
}
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Demo.Console/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ private void OnDarkThemeRadioButtonChecked(object sender, RoutedEventArgs e)
private string GetAssemblyVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? String.Empty;
?? string.Empty;
}
}
1 change: 1 addition & 0 deletions src/Wpf.Ui.Demo.Console/Wpf.Ui.Demo.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>wpfui.ico</ApplicationIcon>
<NoWarn>$(NoWarn);SA1601</NoWarn>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
34 changes: 18 additions & 16 deletions src/Wpf.Ui.Demo.Mvvm/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand Down Expand Up @@ -26,40 +26,42 @@ public partial class App
private static readonly IHost _host = Host.CreateDefaultBuilder()
.ConfigureAppConfiguration(c =>
{
c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory));
var basePath = Path.GetDirectoryName(AppContext.BaseDirectory)
?? throw new DirectoryNotFoundException("Unable to find the base directory of the application.");
_ = c.SetBasePath(basePath);
})
.ConfigureServices(
(context, services) =>
{
// App Host
services.AddHostedService<ApplicationHostService>();
_ = services.AddHostedService<ApplicationHostService>();

// Page resolver service
services.AddSingleton<IPageService, PageService>();
_ = services.AddSingleton<IPageService, PageService>();

// Theme manipulation
services.AddSingleton<IThemeService, ThemeService>();
_ = services.AddSingleton<IThemeService, ThemeService>();

// TaskBar manipulation
services.AddSingleton<ITaskBarService, TaskBarService>();
_ = services.AddSingleton<ITaskBarService, TaskBarService>();

// Service containing navigation, same as INavigationWindow... but without window
services.AddSingleton<INavigationService, NavigationService>();
_ = services.AddSingleton<INavigationService, NavigationService>();

// Main window with navigation
services.AddSingleton<INavigationWindow, Views.MainWindow>();
services.AddSingleton<ViewModels.MainWindowViewModel>();
_ = services.AddSingleton<INavigationWindow, Views.MainWindow>();
_ = services.AddSingleton<ViewModels.MainWindowViewModel>();

// Views and ViewModels
services.AddSingleton<Views.Pages.DashboardPage>();
services.AddSingleton<ViewModels.DashboardViewModel>();
services.AddSingleton<Views.Pages.DataPage>();
services.AddSingleton<ViewModels.DataViewModel>();
services.AddSingleton<Views.Pages.SettingsPage>();
services.AddSingleton<ViewModels.SettingsViewModel>();
_ = services.AddSingleton<Views.Pages.DashboardPage>();
_ = services.AddSingleton<ViewModels.DashboardViewModel>();
_ = services.AddSingleton<Views.Pages.DataPage>();
_ = services.AddSingleton<ViewModels.DataViewModel>();
_ = services.AddSingleton<Views.Pages.SettingsPage>();
_ = services.AddSingleton<ViewModels.SettingsViewModel>();

// Configuration
services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
_ = services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
}
)
.Build();
Expand Down
10 changes: 2 additions & 8 deletions src/Wpf.Ui.Demo.Mvvm/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

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)
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)
)]
12 changes: 9 additions & 3 deletions src/Wpf.Ui.Demo.Mvvm/Helpers/EnumToBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand All @@ -12,11 +12,15 @@ internal class EnumToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter is not String enumString)
if (parameter is not string enumString)
{
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
}

if (!Enum.IsDefined(typeof(Wpf.Ui.Appearance.ApplicationTheme), value))
{
throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum");
}

var enumValue = Enum.Parse(typeof(Wpf.Ui.Appearance.ApplicationTheme), enumString);

Expand All @@ -25,8 +29,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter is not String enumString)
if (parameter is not string enumString)
{
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
}

return Enum.Parse(typeof(Wpf.Ui.Appearance.ApplicationTheme), enumString);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Wpf.Ui.Demo.Mvvm/Models/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand All @@ -7,7 +7,7 @@ namespace Wpf.Ui.Demo.Mvvm.Models;

public class AppConfig
{
public string ConfigurationsFolder { get; set; }
public string? ConfigurationsFolder { get; set; }

public string AppPropertiesFileName { get; set; }
public string? AppPropertiesFileName { get; set; }
}
6 changes: 3 additions & 3 deletions src/Wpf.Ui.Demo.Mvvm/Services/ApplicationHostService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand All @@ -14,7 +14,7 @@ namespace Wpf.Ui.Demo.Mvvm.Services;
public class ApplicationHostService : IHostedService
{
private readonly IServiceProvider _serviceProvider;
private INavigationWindow _navigationWindow;
private INavigationWindow? _navigationWindow;

public ApplicationHostService(IServiceProvider serviceProvider)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ private async Task HandleActivationAsync()
)!;
_navigationWindow!.ShowWindow();

_navigationWindow.Navigate(typeof(Views.Pages.DashboardPage));
_ = _navigationWindow.Navigate(typeof(Views.Pages.DashboardPage));
}

await Task.CompletedTask;
Expand Down
8 changes: 6 additions & 2 deletions src/Wpf.Ui.Demo.Mvvm/Services/PageService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand All @@ -16,7 +16,7 @@ public class PageService : IPageService
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Creates new instance and attaches the <see cref="IServiceProvider"/>.
/// Initializes a new instance of the <see cref="PageService"/> class and attaches the <see cref="IServiceProvider"/>.
/// </summary>
public PageService(IServiceProvider serviceProvider)
{
Expand All @@ -28,7 +28,9 @@ public PageService(IServiceProvider serviceProvider)
where T : class
{
if (!typeof(FrameworkElement).IsAssignableFrom(typeof(T)))
{
throw new InvalidOperationException("The page should be a WPF control.");
}

return (T?)_serviceProvider.GetService(typeof(T));
}
Expand All @@ -37,7 +39,9 @@ public PageService(IServiceProvider serviceProvider)
public FrameworkElement? GetPage(Type pageType)
{
if (!typeof(FrameworkElement).IsAssignableFrom(pageType))
{
throw new InvalidOperationException("The page should be a WPF control.");
}

return _serviceProvider.GetService(pageType) as FrameworkElement;
}
Expand Down
14 changes: 8 additions & 6 deletions src/Wpf.Ui.Demo.Mvvm/ViewModels/DataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the MIT License.
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
Expand All @@ -14,23 +14,26 @@ public partial class DataViewModel : ObservableObject, INavigationAware
private bool _isInitialized = false;

[ObservableProperty]
private IEnumerable<DataColor> _colors;
private List<DataColor> _colors = [];

public void OnNavigatedTo()
{
if (!_isInitialized)
{
InitializeViewModel();
}
}

public void OnNavigatedFrom() { }

private void InitializeViewModel()
{
var random = new Random();
var colorCollection = new List<DataColor>();
Colors.Clear();

for (int i = 0; i < 8192; i++)
colorCollection.Add(
{
Colors.Add(
new DataColor
{
Color = new SolidColorBrush(
Expand All @@ -43,8 +46,7 @@ private void InitializeViewModel()
)
}
);

Colors = colorCollection;
}

_isInitialized = true;
}
Expand Down
Loading
Loading