diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index d23d2c79bd..4a557498d8 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -1853,6 +1853,7 @@ timeunion
timeutil
timezones
Titlecase
+TKey
TLayout
tlb
TMPVAR
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 7b11df8764..c56ffd4843 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -18,7 +18,7 @@
-
+
diff --git a/NOTICE.md b/NOTICE.md
index 79ac437363..bb2270aae9 100644
--- a/NOTICE.md
+++ b/NOTICE.md
@@ -289,7 +289,7 @@ SOFTWARE.
- LazyCache 2.4.0
- Mages 2.0.1
- Markdig.Signed 0.27.0
-- Microsoft.CodeAnalysis.NetAnalyzers 7.0.0
+- Microsoft.CodeAnalysis.NetAnalyzers 7.0.1
- Microsoft.Data.Sqlite 7.0.0
- Microsoft.Extensions.Hosting 7.0.0
- Microsoft.NET.Test.Sdk 17.4.1
diff --git a/src/common/AllExperiments/Experiments.cs b/src/common/AllExperiments/Experiments.cs
index 9663c28b96..38ac694637 100644
--- a/src/common/AllExperiments/Experiments.cs
+++ b/src/common/AllExperiments/Experiments.cs
@@ -2,8 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Numerics;
-using System.Runtime.InteropServices;
+using System.Globalization;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Telemetry;
@@ -13,10 +12,10 @@ using Windows.System.Profile;
namespace AllExperiments
{
-// The dependencies required to build this project are only available in the official build pipeline and are internal to Microsoft.
-// However, this project is not required to build a test version of the application.
+ // The dependencies required to build this project are only available in the official build pipeline and are internal to Microsoft.
+ // However, this project is not required to build a test version of the application.
public class Experiments
- {
+ {
public enum ExperimentState
{
Enabled,
@@ -25,7 +24,9 @@ namespace AllExperiments
}
#pragma warning disable SA1401 // Need to use LandingPageExperiment as a static property in OobeShellPage.xaml.cs
+#pragma warning disable CA2211 // Non-constant fields should not be visible
public static ExperimentState LandingPageExperiment = ExperimentState.NotLoaded;
+#pragma warning restore CA2211
#pragma warning restore SA1401
public async Task EnableLandingPageExperimentAsync()
@@ -87,7 +88,7 @@ namespace AllExperiments
else
{
var jsonDataVersion = jsonDictionary["dataversion"].ToString();
- if (jsonDataVersion != null && int.Parse(jsonDataVersion) < dataVersion)
+ if (jsonDataVersion != null && int.Parse(jsonDataVersion, CultureInfo.InvariantCulture) < dataVersion)
{
jsonDictionary["dataversion"] = dataVersion;
jsonDictionary["variantassignment"] = featureFlagValue;
diff --git a/src/common/AllExperiments/Microsoft.VariantAssignment/Client/VariantAssignmentServiceClient.cs b/src/common/AllExperiments/Microsoft.VariantAssignment/Client/VariantAssignmentServiceClient.cs
index f90952859a..373651f83a 100644
--- a/src/common/AllExperiments/Microsoft.VariantAssignment/Client/VariantAssignmentServiceClient.cs
+++ b/src/common/AllExperiments/Microsoft.VariantAssignment/Client/VariantAssignmentServiceClient.cs
@@ -7,7 +7,7 @@ using Microsoft.VariantAssignment.Contract;
// The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects
namespace Microsoft.VariantAssignment.Client
{
- internal partial class VariantAssignmentServiceClient : IVariantAssignmentProvider, IDisposable
+ internal sealed partial class VariantAssignmentServiceClient : IVariantAssignmentProvider, IDisposable
where TServerResponse : VariantAssignmentServiceResponse
{
public void Dispose()
diff --git a/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/EmptyVariantAssignmentResponse.cs b/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/EmptyVariantAssignmentResponse.cs
index 90c797155e..0e0cd54094 100644
--- a/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/EmptyVariantAssignmentResponse.cs
+++ b/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/EmptyVariantAssignmentResponse.cs
@@ -31,7 +31,13 @@ namespace Microsoft.VariantAssignment.Contract
///
public IReadOnlyList GetFeatureVariables(IReadOnlyList prefix) => Array.Empty();
- void IDisposable.Dispose()
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
{
}
diff --git a/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/TreatmentAssignmentServiceResponse.cs b/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/TreatmentAssignmentServiceResponse.cs
index 3b082549f7..6db91f6ffd 100644
--- a/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/TreatmentAssignmentServiceResponse.cs
+++ b/src/common/AllExperiments/Microsoft.VariantAssignment/Contract/TreatmentAssignmentServiceResponse.cs
@@ -5,7 +5,7 @@
// The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects
namespace Microsoft.VariantAssignment.Contract
{
- internal class TreatmentAssignmentServiceResponse : VariantAssignmentServiceResponse
+ internal sealed class TreatmentAssignmentServiceResponse : VariantAssignmentServiceResponse
{
}
}
diff --git a/src/modules/Hosts/Hosts/Helpers/ExpressionExtensions.cs b/src/modules/Hosts/Hosts/Helpers/ExpressionExtensions.cs
index b2e0a0eeef..a72265ab24 100644
--- a/src/modules/Hosts/Hosts/Helpers/ExpressionExtensions.cs
+++ b/src/modules/Hosts/Hosts/Helpers/ExpressionExtensions.cs
@@ -23,7 +23,7 @@ namespace Hosts.Helpers
return new ReplaceVisitor(searchEx, replaceEx).Visit(expression);
}
- internal class ReplaceVisitor : ExpressionVisitor
+ internal sealed class ReplaceVisitor : ExpressionVisitor
{
private readonly Expression _from;
private readonly Expression _to;
diff --git a/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs b/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs
index bff5f3db4f..9db941164b 100644
--- a/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs
+++ b/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs
@@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
namespace Hosts.Helpers
{
- internal class NativeMethods
+ internal sealed class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);
diff --git a/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs b/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
index 5c20675127..05fd3c1d16 100644
--- a/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
+++ b/src/modules/Hosts/Hosts/ViewModels/MainViewModel.cs
@@ -328,8 +328,8 @@ namespace Hosts.ViewModels
private void FindDuplicates(string address, IEnumerable hosts)
{
var entries = _entries.Where(e =>
- string.Equals(e.Address, address, StringComparison.InvariantCultureIgnoreCase)
- || hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any());
+ string.Equals(e.Address, address, StringComparison.OrdinalIgnoreCase)
+ || hosts.Intersect(e.SplittedHosts, StringComparer.OrdinalIgnoreCase).Any());
foreach (var entry in entries)
{
@@ -353,8 +353,8 @@ namespace Hosts.ViewModels
var duplicate = _entries.FirstOrDefault(e => e != entry
&& e.Type == entry.Type
- && (string.Equals(e.Address, entry.Address, StringComparison.InvariantCultureIgnoreCase)
- || hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any())) != null;
+ && (string.Equals(e.Address, entry.Address, StringComparison.OrdinalIgnoreCase)
+ || hosts.Intersect(e.SplittedHosts, StringComparer.OrdinalIgnoreCase).Any())) != null;
_dispatcherQueue.TryEnqueue(() =>
{
diff --git a/src/modules/PowerOCR/PowerOCR/Helpers/ImageMethods.cs b/src/modules/PowerOCR/PowerOCR/Helpers/ImageMethods.cs
index d5fa1a49ab..85fdae3083 100644
--- a/src/modules/PowerOCR/PowerOCR/Helpers/ImageMethods.cs
+++ b/src/modules/PowerOCR/PowerOCR/Helpers/ImageMethods.cs
@@ -24,7 +24,7 @@ using BitmapDecoder = Windows.Graphics.Imaging.BitmapDecoder;
namespace PowerOCR;
-internal class ImageMethods
+internal sealed class ImageMethods
{
internal static ImageSource GetWindowBoundsImage(Window passedWindow)
{
diff --git a/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs b/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs
index 14d213c151..e0cf0a7ac5 100644
--- a/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs
+++ b/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs
@@ -12,7 +12,7 @@ namespace PowerOCR.Keyboard
/// This class handles the interaction model when running from PowerToys Run.
/// Handles activation through the event sent by the runner.
///
- internal class EventMonitor
+ internal sealed class EventMonitor
{
public EventMonitor(System.Windows.Threading.Dispatcher dispatcher, System.Threading.CancellationToken exitToken)
{
diff --git a/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHook.cs b/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHook.cs
index 3ffe94c2e0..34f0f77160 100644
--- a/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHook.cs
+++ b/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHook.cs
@@ -10,7 +10,7 @@ using static PowerOCR.OSInterop;
namespace PowerOCR.Keyboard;
-internal class GlobalKeyboardHook : IDisposable
+internal sealed class GlobalKeyboardHook : IDisposable
{
private IntPtr _windowsHookHandle;
private IntPtr _user32LibraryHandle;
@@ -39,7 +39,7 @@ internal class GlobalKeyboardHook : IDisposable
internal event EventHandler? KeyboardPressed;
- protected virtual void Dispose(bool disposing)
+ public void Dispose(bool disposing)
{
if (disposing)
{
diff --git a/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHookEventArgs.cs b/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHookEventArgs.cs
index b20bcd645a..23360de470 100644
--- a/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHookEventArgs.cs
+++ b/src/modules/PowerOCR/PowerOCR/Keyboard/GlobalKeyboardHookEventArgs.cs
@@ -7,7 +7,7 @@ using static PowerOCR.OSInterop;
namespace PowerOCR.Keyboard;
-internal class GlobalKeyboardHookEventArgs : HandledEventArgs
+internal sealed class GlobalKeyboardHookEventArgs : HandledEventArgs
{
internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }
diff --git a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
index 5b66d0b937..4a0f8811c9 100644
--- a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
+++ b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
@@ -35,7 +35,7 @@ public partial class OCROverlay : Window
private Point GetMousePos() => PointToScreen(Mouse.GetPosition(this));
- private Language? selectedLanguage = null;
+ private Language? selectedLanguage;
private MenuItem cancelMenuItem;
private System.Windows.Forms.Screen? CurrentScreen
@@ -70,8 +70,8 @@ public partial class OCROverlay : Window
foreach (Language language in possibleOcrLanguages)
{
MenuItem menuItem = new MenuItem() { Header = language.NativeName, Tag = language, IsCheckable = true };
- menuItem.IsChecked = language.DisplayName.Equals(selectedLanguageName);
- if (language.DisplayName.Equals(selectedLanguageName))
+ menuItem.IsChecked = language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal);
+ if (language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal))
{
selectedLanguage = language;
}
diff --git a/src/modules/awake/Awake/Program.cs b/src/modules/awake/Awake/Program.cs
index 68cfe5c9e7..1d016300ff 100644
--- a/src/modules/awake/Awake/Program.cs
+++ b/src/modules/awake/Awake/Program.cs
@@ -7,6 +7,7 @@ using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
using System.Drawing;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Reactive.Concurrency;
@@ -255,7 +256,7 @@ namespace Awake
{
try
{
- DateTime expirationDateTime = DateTime.Parse(expireAt);
+ DateTime expirationDateTime = DateTime.Parse(expireAt, CultureInfo.CurrentCulture);
if (expirationDateTime > DateTime.Now)
{
// We want to have a dedicated expirable keep-awake logic instead of
diff --git a/src/modules/awake/Awake/Telemetry/AwakeNoKeepAwakeEvent.cs b/src/modules/awake/Awake/Telemetry/AwakeNoKeepAwakeEvent.cs
index f9a696d8be..be52e82377 100644
--- a/src/modules/awake/Awake/Telemetry/AwakeNoKeepAwakeEvent.cs
+++ b/src/modules/awake/Awake/Telemetry/AwakeNoKeepAwakeEvent.cs
@@ -9,7 +9,7 @@ using Microsoft.PowerToys.Telemetry.Events;
namespace Awake.Telemetry
{
[EventData]
- internal class AwakeNoKeepAwakeEvent : EventBase, IEvent
+ internal sealed class AwakeNoKeepAwakeEvent : EventBase, IEvent
{
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs
index ae747b0d58..e09c494e36 100644
--- a/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs
+++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs
@@ -246,9 +246,7 @@ namespace ColorPicker.ViewModels
new ColorFormatModel()
{
FormatName = ColorRepresentationType.HEX.ToString(),
-#pragma warning disable CA1304 // Specify CultureInfo
- Convert = (Color color) => ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX.ToString()).ToLower(),
-#pragma warning restore CA1304 // Specify CultureInfo
+ Convert = (Color color) => ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX.ToString()).ToLowerInvariant(),
});
_allColorRepresentations.Add(
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs
index f55813bf4c..ac9c8ac7c3 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasZone.xaml.cs
@@ -159,7 +159,7 @@ namespace FancyZonesEditor
public abstract void Move(int delta);
}
- private class SnappyHelperMagnetic : SnappyHelperBase
+ private sealed class SnappyHelperMagnetic : SnappyHelperBase
{
private List magnetZoneSizes;
private int freePosition;
@@ -220,7 +220,7 @@ namespace FancyZonesEditor
}
}
- private class SnappyHelperNonMagnetic : SnappyHelperBase
+ private sealed class SnappyHelperNonMagnetic : SnappyHelperBase
{
public SnappyHelperNonMagnetic(IList zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisOrigin, int screenAxisSize)
: base(zones, zoneIndex, isX, mode, screenAxisOrigin, screenAxisSize)
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs
index ba006e2c13..01e17f70b8 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs
@@ -8,7 +8,7 @@ using System.Windows.Controls;
namespace FancyZonesEditor.Controls
{
- internal class CustomSliderAutomationPeer : SliderAutomationPeer
+ internal sealed class CustomSliderAutomationPeer : SliderAutomationPeer
{
private string name = string.Empty;
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
index 4a14b82e44..26b0dfa151 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
@@ -175,7 +175,7 @@ namespace FancyZonesEditor.Utils
}
// custom-layouts.json
- private class CanvasInfoWrapper
+ private sealed class CanvasInfoWrapper
{
public struct CanvasZoneWrapper
{
@@ -198,7 +198,7 @@ namespace FancyZonesEditor.Utils
}
// custom-layouts.json
- private class GridInfoWrapper
+ private sealed class GridInfoWrapper
{
public int Rows { get; set; }
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/NativeMethods.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/NativeMethods.cs
index 57cefcf9be..b5d4db9952 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/NativeMethods.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/NativeMethods.cs
@@ -9,7 +9,7 @@ using System.Windows.Interop;
namespace FancyZonesEditor.Utils
{
- internal class NativeMethods
+ internal sealed class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
diff --git a/src/modules/imageresizer/tests/Test/AssertEx.cs b/src/modules/imageresizer/tests/Test/AssertEx.cs
index 5c05ecec44..7961b6f22f 100644
--- a/src/modules/imageresizer/tests/Test/AssertEx.cs
+++ b/src/modules/imageresizer/tests/Test/AssertEx.cs
@@ -75,7 +75,7 @@ namespace ImageResizer.Test
return raisedEvent;
}
- public class RaisedEvent
+ public sealed class RaisedEvent
{
public RaisedEvent(object sender, TArgs args)
{
diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs
index aa25ceb994..bb72b6fa2c 100644
--- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs
+++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs
@@ -62,7 +62,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
return new Result
{
ContextData = result,
- Title = result.ToString(),
+ Title = result.ToString(null),
IcoPath = _icon_path,
Score = 300,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.copy_to_clipboard, result.QuantityInfo.Name),
diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/SystemPath.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/SystemPath.cs
index 3b76c8cafc..f937e5e9d4 100644
--- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/SystemPath.cs
+++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/SystemPath.cs
@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
{
- internal class SystemPath
+ internal sealed class SystemPath
{
private static readonly Regex WindowsPath = new Regex(@"^([a-zA-Z]:)", RegexOptions.Compiled);
diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs
index 04316a3a91..737cc1559d 100644
--- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs
+++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWPApplication.cs
@@ -439,9 +439,9 @@ namespace Microsoft.Plugin.Program.Programs
paths.Add(path);
}
- if (_scaleFactors.ContainsKey(Package.Version))
+ if (_scaleFactors.TryGetValue(Package.Version, out List factors))
{
- foreach (var factor in _scaleFactors[Package.Version])
+ foreach (var factor in factors)
{
if (highContrast)
{
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
index cda615809d..c681ae0e03 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
@@ -17,7 +17,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
///
/// This class represents the informations for a network connection/interface
///
- internal class NetworkConnectionProperties
+ internal sealed class NetworkConnectionProperties
{
///
/// Gets the name of the adapter
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs
index c6d26c8624..20840e0db3 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs
@@ -4,7 +4,7 @@
namespace Microsoft.PowerToys.Run.Plugin.System.Components
{
- internal class SystemPluginContext
+ internal sealed class SystemPluginContext
{
///
/// Gets or sets the type of the result
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSetting.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSetting.cs
index 8065dc46a1..8b4d1591bd 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSetting.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSetting.cs
@@ -9,7 +9,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
///
/// A windows setting
///
- internal class WindowsSetting
+ internal sealed class WindowsSetting
{
///
/// Initializes a new instance of the class.
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSettings.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSettings.cs
index 7ce25eb499..e05532cc4b 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSettings.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Classes/WindowsSettings.cs
@@ -10,7 +10,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
///
/// A class that contain all possible windows settings
///
- internal class WindowsSettings
+ internal sealed class WindowsSettings
{
///
/// Initializes a new instance of the class with an empty settings list.
diff --git a/src/modules/launcher/PowerLauncher/CustomSearchBox.cs b/src/modules/launcher/PowerLauncher/CustomSearchBox.cs
index 5502fd15c9..20b1becf39 100644
--- a/src/modules/launcher/PowerLauncher/CustomSearchBox.cs
+++ b/src/modules/launcher/PowerLauncher/CustomSearchBox.cs
@@ -9,7 +9,7 @@ using System.Windows.Controls;
namespace PowerLauncher
{
- public class CustomSearchBox : TextBox
+ public sealed class CustomSearchBox : TextBox
{
public List ControlledElements { get; } = new List();
@@ -18,7 +18,7 @@ namespace PowerLauncher
return new AutoSuggestTextBoxAutomationPeer(this);
}
- internal class AutoSuggestTextBoxAutomationPeer : TextBoxAutomationPeer
+ internal sealed class AutoSuggestTextBoxAutomationPeer : TextBoxAutomationPeer
{
public AutoSuggestTextBoxAutomationPeer(CustomSearchBox owner)
: base(owner)
diff --git a/src/modules/launcher/PowerLauncher/Helper/KeyboardHelper.cs b/src/modules/launcher/PowerLauncher/Helper/KeyboardHelper.cs
index 6cfdd2fded..97a05cfac4 100644
--- a/src/modules/launcher/PowerLauncher/Helper/KeyboardHelper.cs
+++ b/src/modules/launcher/PowerLauncher/Helper/KeyboardHelper.cs
@@ -7,7 +7,7 @@ using Wox.Plugin;
namespace PowerLauncher.Helper
{
- internal class KeyboardHelper
+ internal sealed class KeyboardHelper
{
public static SpecialKeyState CheckModifiers()
{
diff --git a/src/modules/launcher/PowerLauncher/ReportWindow.xaml.cs b/src/modules/launcher/PowerLauncher/ReportWindow.xaml.cs
index 1ed201413c..804c162511 100644
--- a/src/modules/launcher/PowerLauncher/ReportWindow.xaml.cs
+++ b/src/modules/launcher/PowerLauncher/ReportWindow.xaml.cs
@@ -17,7 +17,7 @@ using Wox.Plugin.Logger;
namespace PowerLauncher
{
- internal partial class ReportWindow
+ internal sealed partial class ReportWindow
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IFile File = FileSystem.File;
diff --git a/src/modules/launcher/PowerLauncher/SettingsReader.cs b/src/modules/launcher/PowerLauncher/SettingsReader.cs
index e470f85749..98abae4318 100644
--- a/src/modules/launcher/PowerLauncher/SettingsReader.cs
+++ b/src/modules/launcher/PowerLauncher/SettingsReader.cs
@@ -269,9 +269,9 @@ namespace PowerLauncher
var defaultOptions = defaultAdditionalOptions.ToDictionary(x => x.Key);
foreach (var option in additionalOptions)
{
- if (option.Key != null && defaultOptions.ContainsKey(option.Key))
+ if (option.Key != null && defaultOptions.TryGetValue(option.Key, out PluginAdditionalOption defaultOption))
{
- defaultOptions[option.Key].Value = option.Value;
+ defaultOption.Value = option.Value;
}
}
diff --git a/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs b/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs
index 1aa1b4ea36..8a35469178 100644
--- a/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs
+++ b/src/modules/launcher/Wox.Infrastructure/Hotkey/HotkeyModel.cs
@@ -154,9 +154,7 @@ namespace Wox.Infrastructure.Hotkey
if (CharKey != Key.None)
{
- text += _specialSymbolDictionary.ContainsKey(CharKey)
- ? _specialSymbolDictionary[CharKey]
- : CharKey.ToString();
+ text += _specialSymbolDictionary.TryGetValue(CharKey, out string value) ? value : CharKey.ToString();
}
else if (!string.IsNullOrEmpty(text))
{
diff --git a/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs b/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs
index 69acf84dd2..0846391a01 100644
--- a/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs
+++ b/src/modules/launcher/Wox.Infrastructure/Image/ImageHashGenerator.cs
@@ -34,12 +34,7 @@ namespace Wox.Infrastructure.Image
enc.Frames.Add(bitmapFrame);
enc.Save(outStream);
var byteArray = outStream.GetBuffer();
-
- using (var sha1 = SHA1.Create())
- {
- var hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
- return hash;
- }
+ return Convert.ToBase64String(SHA1.HashData(byteArray));
}
}
catch (System.Exception e)
diff --git a/src/modules/launcher/Wox.Plugin/Common/ShellLocalization.cs b/src/modules/launcher/Wox.Plugin/Common/ShellLocalization.cs
index 97ff8bda38..2ea86afd02 100644
--- a/src/modules/launcher/Wox.Plugin/Common/ShellLocalization.cs
+++ b/src/modules/launcher/Wox.Plugin/Common/ShellLocalization.cs
@@ -25,9 +25,9 @@ namespace Wox.Plugin.Common
public string GetLocalizedName(string path)
{
// Checking cache if path is already localized
- if (_localizationCache.ContainsKey(path.ToLowerInvariant()))
+ if (_localizationCache.TryGetValue(path.ToLowerInvariant(), out string value))
{
- return _localizationCache[path.ToLowerInvariant()];
+ return value;
}
Guid shellItemType = ShellItemTypeConstants.ShellItemGuid;
diff --git a/src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs b/src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs
index a987eefad1..44ed05640a 100644
--- a/src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs
+++ b/src/modules/launcher/Wox.Plugin/UserSelectedRecord.cs
@@ -39,11 +39,7 @@ namespace Wox.Plugin
throw new ArgumentNullException(nameof(result));
}
- var key = result.ToString();
- if (Records.ContainsKey(result.ToString()))
- {
- Records.Remove(result.ToString());
- }
+ Records.Remove(result.ToString());
}
public void Add(Result result)
diff --git a/src/modules/launcher/Wox.Test/WoxTest.cs b/src/modules/launcher/Wox.Test/WoxTest.cs
index d682d300cc..6d35aeda66 100644
--- a/src/modules/launcher/Wox.Test/WoxTest.cs
+++ b/src/modules/launcher/Wox.Test/WoxTest.cs
@@ -14,7 +14,7 @@ namespace Wox.Test
public class WoxTest
{
// A Dummy class to test that OnPropertyChanged() is called while we set the variable
- private class DummyTestClass : BaseModel
+ private sealed class DummyTestClass : BaseModel
{
public bool IsFunctionCalled { get; set; }
diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs
index 2b5ad8615c..2ca2ac8d50 100644
--- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs
+++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs
@@ -2,9 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using PowerToys.PowerAccentKeyboardService;
-using Windows.Globalization;
namespace PowerAccent.Core
{
@@ -42,7 +40,7 @@ namespace PowerAccent.Core
TK,
}
- internal class Languages
+ internal sealed class Languages
{
public static string[] GetDefaultLetterKey(LetterKey letter, Language lang)
{
diff --git a/src/modules/poweraccent/PowerAccent.Core/Tools/CharactersUsageInfo.cs b/src/modules/poweraccent/PowerAccent.Core/Tools/CharactersUsageInfo.cs
index 6dec635eac..1429be6f34 100644
--- a/src/modules/poweraccent/PowerAccent.Core/Tools/CharactersUsageInfo.cs
+++ b/src/modules/poweraccent/PowerAccent.Core/Tools/CharactersUsageInfo.cs
@@ -34,6 +34,7 @@ namespace PowerAccent.Core.Tools
return timestamp;
}
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1854:Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method", Justification = "False positive: https://github.com/dotnet/roslyn-analyzers/issues/6390")]
public void IncrementUsageFrequency(string character)
{
if (_characterUsageCounters.ContainsKey(character))
diff --git a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs
index d243c3f20d..f83e20c037 100644
--- a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs
+++ b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs
@@ -17,7 +17,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
private Visibility _characterNameVisibility = Visibility.Visible;
- private int _selectedIndex = 0;
+ private int _selectedIndex;
public event PropertyChangedEventHandler PropertyChanged;
diff --git a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/FormHandlerControlTests.cs b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/FormHandlerControlTests.cs
index b1fd46d5bc..c4369063d4 100644
--- a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/FormHandlerControlTests.cs
+++ b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/FormHandlerControlTests.cs
@@ -13,7 +13,7 @@ namespace PreviewHandlerCommonUnitTests
[TestClass]
public class FormHandlerControlTests
{
- private class TestFormControl : FormHandlerControl
+ private sealed class TestFormControl : FormHandlerControl
{
}
diff --git a/src/modules/previewpane/common/cominterop/NativeMethods.cs b/src/modules/previewpane/common/cominterop/NativeMethods.cs
index 3d7bebaef2..611136b1a3 100644
--- a/src/modules/previewpane/common/cominterop/NativeMethods.cs
+++ b/src/modules/previewpane/common/cominterop/NativeMethods.cs
@@ -10,7 +10,7 @@ namespace PreviewHandlerCommon.ComInterop
///
/// Interop methods
///
- internal class NativeMethods
+ internal sealed class NativeMethods
{
///
/// Changes the parent window of the specified child window.
diff --git a/src/modules/previewpane/common/controls/FormHandlerControl.cs b/src/modules/previewpane/common/controls/FormHandlerControl.cs
index 7549933382..ab5cfe6a91 100644
--- a/src/modules/previewpane/common/controls/FormHandlerControl.cs
+++ b/src/modules/previewpane/common/controls/FormHandlerControl.cs
@@ -73,7 +73,7 @@ namespace Common
}
///
- public void SetRect(Rectangle rect)
+ public void SetRect(Rectangle windowBounds)
{
this.UpdateWindowBounds(parentHwnd);
}
diff --git a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs
index dbb619ea73..64143f716a 100644
--- a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs
+++ b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs
@@ -60,7 +60,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
private bool FilterKeyboardEvents(KeyboardEvent ev)
{
+#pragma warning disable CA2020 // Prevent from behavioral change
return _filterKeyboardEvent(ev.key, (UIntPtr)ev.dwExtraInfo);
+#pragma warning restore CA2020 // Prevent from behavioral change
}
protected virtual void Dispose(bool disposing)
diff --git a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
index eeaa0aa541..36bed6bf48 100644
--- a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
+++ b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs
@@ -46,7 +46,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
- private class JsonMergeHelper
+ private sealed class JsonMergeHelper
{
// mostly from https://stackoverflow.com/questions/58694837/system-text-json-merge-two-objects
// but with some update to prevent array item duplicates
@@ -308,10 +308,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
var retoreFullPath = Path.Combine(appBasePath, relativePath);
var settingsToRestoreJson = GetExportVersion(backupRetoreSettings, currentFile.Key, currentFile.Value);
- if (currentSettingsFiles.ContainsKey(currentFile.Key))
+ if (currentSettingsFiles.TryGetValue(currentFile.Key, out string value))
{
// we have a setting file to restore to
- var currentSettingsFileJson = GetExportVersion(backupRetoreSettings, currentFile.Key, currentSettingsFiles[currentFile.Key]);
+ var currentSettingsFileJson = GetExportVersion(backupRetoreSettings, currentFile.Key, value);
if (JsonNormalizer.Normalize(settingsToRestoreJson) != JsonNormalizer.Normalize(currentSettingsFileJson))
{
@@ -659,10 +659,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
var currentSettingsFileToBackup = GetExportVersion(backupRetoreSettings, currentFile.Key, currentFile.Value);
var doBackup = false;
- if (lastBackupSettingsFiles.ContainsKey(currentFile.Key))
+ if (lastBackupSettingsFiles.TryGetValue(currentFile.Key, out string value))
{
// there is a previous backup for this, get an export version of it.
- var lastSettingsFileDoc = GetExportVersion(backupRetoreSettings, currentFile.Key, lastBackupSettingsFiles[currentFile.Key]);
+ var lastSettingsFileDoc = GetExportVersion(backupRetoreSettings, currentFile.Key, value);
// check to see if the new export version would be same as last export version.
if (JsonNormalizer.Normalize(currentSettingsFileToBackup) != JsonNormalizer.Normalize(lastSettingsFileDoc))
@@ -989,7 +989,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// Class JsonNormalizer is a utility class to 'normalize' a JSON file so that it can be compared to another JSON file.
/// This really just means to fully sort it. This does not work for any JSON file where the order of the node is relevant.
///
- private class JsonNormalizer
+ private sealed class JsonNormalizer
{
public static string Normalize(string json)
{
diff --git a/src/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs b/src/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs
index 7827023cc2..f7b25470e2 100644
--- a/src/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs
+++ b/src/settings-ui/Settings.UI.UnitTests/BackwardsCompatibility/BackCompatTestProperties.cs
@@ -20,7 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
// Using Ordinal since this is used internally for a path
private static readonly Expression> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
- internal class MockSettingsRepository : ISettingsRepository
+ internal sealed class MockSettingsRepository : ISettingsRepository
where T : ISettingsConfig, new()
{
private readonly ISettingsUtils _settingsUtils;
diff --git a/src/settings-ui/Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs b/src/settings-ui/Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs
index 56b7701c9f..62e7f7b9af 100644
--- a/src/settings-ui/Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs
+++ b/src/settings-ui/Settings.UI.UnitTests/ModelsTests/SettingsUtilsTests.cs
@@ -100,7 +100,7 @@ namespace CommonLibTest
.Select(s => s[random.Next(s.Length)]).ToArray());
}
- private partial class TestClass : ISettingsConfig
+ private sealed partial class TestClass : ISettingsConfig
{
public int TestInt { get; set; } = 100;
diff --git a/src/settings-ui/Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs b/src/settings-ui/Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs
index 1c5c0537d8..db54fa96dc 100644
--- a/src/settings-ui/Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs
+++ b/src/settings-ui/Settings.UI.UnitTests/ViewModelTests/PowerLauncherViewModelTest.cs
@@ -14,7 +14,7 @@ namespace ViewModelTests
[TestClass]
public class PowerLauncherViewModelTest
{
- private class SendCallbackMock
+ private sealed class SendCallbackMock
{
public int TimesSent { get; set; }
diff --git a/src/settings-ui/Settings.UI/Activation/DefaultActivationHandler.cs b/src/settings-ui/Settings.UI/Activation/DefaultActivationHandler.cs
index 2c401c4a39..c501a23e6b 100644
--- a/src/settings-ui/Settings.UI/Activation/DefaultActivationHandler.cs
+++ b/src/settings-ui/Settings.UI/Activation/DefaultActivationHandler.cs
@@ -9,7 +9,7 @@ using Windows.ApplicationModel.Activation;
namespace Microsoft.PowerToys.Settings.UI.Activation
{
- internal class DefaultActivationHandler : ActivationHandler
+ internal sealed class DefaultActivationHandler : ActivationHandler
{
private readonly Type navElement;
diff --git a/src/settings-ui/Settings.UI/App.xaml.cs b/src/settings-ui/Settings.UI/App.xaml.cs
index 737c73a378..14512c75e3 100644
--- a/src/settings-ui/Settings.UI/App.xaml.cs
+++ b/src/settings-ui/Settings.UI/App.xaml.cs
@@ -163,8 +163,8 @@ namespace Microsoft.PowerToys.Settings.UI
if (containsFlyoutPosition)
{
// get the flyout position arguments
- int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x);
- int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y);
+ _ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x);
+ _ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y);
}
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
diff --git a/src/settings-ui/Settings.UI/Helpers/Utils.cs b/src/settings-ui/Settings.UI/Helpers/Utils.cs
index 53124c7986..7f34815bf8 100644
--- a/src/settings-ui/Settings.UI/Helpers/Utils.cs
+++ b/src/settings-ui/Settings.UI/Helpers/Utils.cs
@@ -9,7 +9,7 @@ using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Helpers
{
- internal class Utils
+ internal sealed class Utils
{
private static string _placementPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\settings-placement.json");
diff --git a/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs b/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
index b086b52336..cd069e9c60 100644
--- a/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
+++ b/src/settings-ui/Settings.UI/OOBE/Views/OobeWhatsNew.xaml.cs
@@ -25,7 +25,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
public sealed partial class OobeWhatsNew : Page
{
// Contains information for a release. Used to deserialize release JSON info from GitHub.
- private class PowerToysReleaseInfo
+ private sealed class PowerToysReleaseInfo
{
[JsonPropertyName("published_at")]
public DateTimeOffset PublishedDate { get; set; }
diff --git a/src/settings-ui/Settings.UI/Services/ActivationService.cs b/src/settings-ui/Settings.UI/Services/ActivationService.cs
index bf627dd160..0d6d241631 100644
--- a/src/settings-ui/Settings.UI/Services/ActivationService.cs
+++ b/src/settings-ui/Settings.UI/Services/ActivationService.cs
@@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Services
{
// For more information on understanding and extending activation flow see
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
- internal class ActivationService
+ internal sealed class ActivationService
{
private readonly App app;
private readonly Type defaultNavItem;
diff --git a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs
index c9c06e4fd9..6f27fbab83 100644
--- a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs
@@ -241,7 +241,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
// skip entries with empty name or duplicated name, it should never occur
string storedName = storedColorFormat.Key;
- if (storedName == string.Empty || ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(storedName.ToUpperInvariant(), StringComparison.Ordinal)) > 0)
+ if (storedName == string.Empty || ColorFormats.Any(x => x.Name.ToUpperInvariant().Equals(storedName.ToUpperInvariant(), StringComparison.Ordinal)))
{
continue;
}
diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs
index c8b184b2f1..129f961d56 100644
--- a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutMenuItem.cs
@@ -36,7 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
- public Action EnabledChangedCallback { get; set; } = null;
+ public Action EnabledChangedCallback { get; set; }
public bool Visible
{
diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs
index 1d45053b2e..d97237c43f 100644
--- a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs
@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Timers;
@@ -9,8 +10,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
{
- public class FlyoutViewModel
+ public class FlyoutViewModel : IDisposable
{
+ private Timer _hideTimer;
+ private bool _disposed;
+
public bool CanHide { get; set; }
private bool _windows10;
@@ -28,29 +32,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
}
}
- private Timer hideTimer;
-
public FlyoutViewModel()
{
CanHide = true;
- hideTimer = new Timer();
- hideTimer.Elapsed += HideTimer_Elapsed;
- hideTimer.Interval = 1000;
- hideTimer.Enabled = false;
+ _hideTimer = new Timer();
+ _hideTimer.Elapsed += HideTimer_Elapsed;
+ _hideTimer.Interval = 1000;
+ _hideTimer.Enabled = false;
_windows10 = !Helper.Windows11();
}
private void HideTimer_Elapsed(object sender, ElapsedEventArgs e)
{
CanHide = true;
- hideTimer.Stop();
+ _hideTimer.Stop();
}
internal void DisableHiding()
{
CanHide = false;
- hideTimer.Stop();
- hideTimer.Start();
+ _hideTimer.Stop();
+ _hideTimer.Start();
}
public event PropertyChangedEventHandler PropertyChanged;
@@ -59,5 +61,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ _hideTimer?.Dispose();
+ _disposed = true;
+ }
+ }
+ }
}
}
diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs
index 7998a3c1e7..0911051bb1 100644
--- a/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs
+++ b/src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs
@@ -178,12 +178,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
AvailableLanguages.Clear();
foreach (Language language in possibleOcrLanguages)
{
- if (_powerOcrSettings.Properties.PreferredLanguage?.Equals(language.DisplayName) == true)
+ if (_powerOcrSettings.Properties.PreferredLanguage?.Equals(language.DisplayName, StringComparison.Ordinal) == true)
{
preferredLanguageIndex = AvailableLanguages.Count;
}
- if (systemCulture.DisplayName.Equals(language.DisplayName) || systemCulture.Parent.DisplayName.Equals(language.DisplayName))
+ if (systemCulture.DisplayName.Equals(language.DisplayName, StringComparison.Ordinal) || systemCulture.Parent.DisplayName.Equals(language.DisplayName, StringComparison.Ordinal))
{
systemLanguageIndex = AvailableLanguages.Count;
}
diff --git a/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs b/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
index 33effd94b5..35dccfbb50 100644
--- a/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/AwakePage.xaml.cs
@@ -100,7 +100,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
string csMessage = csIpcMessage.ToJsonString();
string outMessage = outIpcMessage.ToJsonString();
- if (!csMessage.Equals(outMessage))
+ if (!csMessage.Equals(outMessage, StringComparison.Ordinal))
{
Logger.LogInfo($"Saved Awake settings from Awake page.");
_sendConfigMsg(outMessage);
diff --git a/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs b/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs
index fdaf5dec21..273fda48d3 100644
--- a/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs
+++ b/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs
@@ -333,7 +333,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
IJsonValue whatToShowJson;
if (json.TryGetValue("ShowYourself", out whatToShowJson))
{
- if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("flyout"))
+ if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("flyout", StringComparison.Ordinal))
{
POINT? p = null;
@@ -351,7 +351,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
OpenFlyoutCallback(p);
}
- else if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("main_page"))
+ else if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("main_page", StringComparison.Ordinal))
{
OpenMainWindowCallback();
}