[Build] Upgraded NetAnalyzers to 7.0.1 (#24792)

* upgraded NetAnalyzers to 7.0.1

* fix spellcheck

* Microsoft.CodeAnalysis.NetAnalyzers 7.0.1

* rebase and fix
This commit is contained in:
Davide Giacometti
2023-03-16 15:51:31 +01:00
committed by GitHub
parent 5492b4ae62
commit 5cbe9dd911
61 changed files with 124 additions and 107 deletions

View File

@@ -1853,6 +1853,7 @@ timeunion
timeutil timeutil
timezones timezones
Titlecase Titlecase
TKey
TLayout TLayout
tlb tlb
TMPVAR TMPVAR

View File

@@ -18,7 +18,7 @@
<PackageVersion Include="LazyCache" Version="2.4.0" /> <PackageVersion Include="LazyCache" Version="2.4.0" />
<PackageVersion Include="Mages" Version="2.0.1" /> <PackageVersion Include="Mages" Version="2.0.1" />
<PackageVersion Include="Markdig.Signed" Version="0.27.0" /> <PackageVersion Include="Markdig.Signed" Version="0.27.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0" /> <PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.0" /> <PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.0" /> <PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" /> <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />

View File

@@ -289,7 +289,7 @@ SOFTWARE.
- LazyCache 2.4.0 - LazyCache 2.4.0
- Mages 2.0.1 - Mages 2.0.1
- Markdig.Signed 0.27.0 - Markdig.Signed 0.27.0
- Microsoft.CodeAnalysis.NetAnalyzers 7.0.0 - Microsoft.CodeAnalysis.NetAnalyzers 7.0.1
- Microsoft.Data.Sqlite 7.0.0 - Microsoft.Data.Sqlite 7.0.0
- Microsoft.Extensions.Hosting 7.0.0 - Microsoft.Extensions.Hosting 7.0.0
- Microsoft.NET.Test.Sdk 17.4.1 - Microsoft.NET.Test.Sdk 17.4.1

View File

@@ -2,8 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Numerics; using System.Globalization;
using System.Runtime.InteropServices;
using System.Text.Json; using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events; using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Telemetry; using Microsoft.PowerToys.Telemetry;
@@ -13,8 +12,8 @@ using Windows.System.Profile;
namespace AllExperiments namespace AllExperiments
{ {
// The dependencies required to build this project are only available in the official build pipeline and are internal to Microsoft. // 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. // However, this project is not required to build a test version of the application.
public class Experiments public class Experiments
{ {
public enum ExperimentState public enum ExperimentState
@@ -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 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; public static ExperimentState LandingPageExperiment = ExperimentState.NotLoaded;
#pragma warning restore CA2211
#pragma warning restore SA1401 #pragma warning restore SA1401
public async Task<bool> EnableLandingPageExperimentAsync() public async Task<bool> EnableLandingPageExperimentAsync()
@@ -87,7 +88,7 @@ namespace AllExperiments
else else
{ {
var jsonDataVersion = jsonDictionary["dataversion"].ToString(); 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["dataversion"] = dataVersion;
jsonDictionary["variantassignment"] = featureFlagValue; jsonDictionary["variantassignment"] = featureFlagValue;

View File

@@ -7,7 +7,7 @@ using Microsoft.VariantAssignment.Contract;
// The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects // The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects
namespace Microsoft.VariantAssignment.Client namespace Microsoft.VariantAssignment.Client
{ {
internal partial class VariantAssignmentServiceClient<TServerResponse> : IVariantAssignmentProvider, IDisposable internal sealed partial class VariantAssignmentServiceClient<TServerResponse> : IVariantAssignmentProvider, IDisposable
where TServerResponse : VariantAssignmentServiceResponse where TServerResponse : VariantAssignmentServiceResponse
{ {
public void Dispose() public void Dispose()

View File

@@ -31,7 +31,13 @@ namespace Microsoft.VariantAssignment.Contract
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyList<IFeatureVariable> GetFeatureVariables(IReadOnlyList<string> prefix) => Array.Empty<IFeatureVariable>(); public IReadOnlyList<IFeatureVariable> GetFeatureVariables(IReadOnlyList<string> prefix) => Array.Empty<IFeatureVariable>();
void IDisposable.Dispose() public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{ {
} }

View File

@@ -5,7 +5,7 @@
// The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects // The goal of this class is to just mock out the Microsoft.VariantAssignment close source objects
namespace Microsoft.VariantAssignment.Contract namespace Microsoft.VariantAssignment.Contract
{ {
internal class TreatmentAssignmentServiceResponse : VariantAssignmentServiceResponse internal sealed class TreatmentAssignmentServiceResponse : VariantAssignmentServiceResponse
{ {
} }
} }

View File

@@ -23,7 +23,7 @@ namespace Hosts.Helpers
return new ReplaceVisitor(searchEx, replaceEx).Visit(expression); return new ReplaceVisitor(searchEx, replaceEx).Visit(expression);
} }
internal class ReplaceVisitor : ExpressionVisitor internal sealed class ReplaceVisitor : ExpressionVisitor
{ {
private readonly Expression _from; private readonly Expression _from;
private readonly Expression _to; private readonly Expression _to;

View File

@@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
namespace Hosts.Helpers namespace Hosts.Helpers
{ {
internal class NativeMethods internal sealed class NativeMethods
{ {
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr SetForegroundWindow(IntPtr hWnd); internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);

View File

@@ -328,8 +328,8 @@ namespace Hosts.ViewModels
private void FindDuplicates(string address, IEnumerable<string> hosts) private void FindDuplicates(string address, IEnumerable<string> hosts)
{ {
var entries = _entries.Where(e => var entries = _entries.Where(e =>
string.Equals(e.Address, address, StringComparison.InvariantCultureIgnoreCase) string.Equals(e.Address, address, StringComparison.OrdinalIgnoreCase)
|| hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any()); || hosts.Intersect(e.SplittedHosts, StringComparer.OrdinalIgnoreCase).Any());
foreach (var entry in entries) foreach (var entry in entries)
{ {
@@ -353,8 +353,8 @@ namespace Hosts.ViewModels
var duplicate = _entries.FirstOrDefault(e => e != entry var duplicate = _entries.FirstOrDefault(e => e != entry
&& e.Type == entry.Type && e.Type == entry.Type
&& (string.Equals(e.Address, entry.Address, StringComparison.InvariantCultureIgnoreCase) && (string.Equals(e.Address, entry.Address, StringComparison.OrdinalIgnoreCase)
|| hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any())) != null; || hosts.Intersect(e.SplittedHosts, StringComparer.OrdinalIgnoreCase).Any())) != null;
_dispatcherQueue.TryEnqueue(() => _dispatcherQueue.TryEnqueue(() =>
{ {

View File

@@ -24,7 +24,7 @@ using BitmapDecoder = Windows.Graphics.Imaging.BitmapDecoder;
namespace PowerOCR; namespace PowerOCR;
internal class ImageMethods internal sealed class ImageMethods
{ {
internal static ImageSource GetWindowBoundsImage(Window passedWindow) internal static ImageSource GetWindowBoundsImage(Window passedWindow)
{ {

View File

@@ -12,7 +12,7 @@ namespace PowerOCR.Keyboard
/// This class handles the interaction model when running from PowerToys Run. /// This class handles the interaction model when running from PowerToys Run.
/// Handles activation through the event sent by the runner. /// Handles activation through the event sent by the runner.
/// </summary> /// </summary>
internal class EventMonitor internal sealed class EventMonitor
{ {
public EventMonitor(System.Windows.Threading.Dispatcher dispatcher, System.Threading.CancellationToken exitToken) public EventMonitor(System.Windows.Threading.Dispatcher dispatcher, System.Threading.CancellationToken exitToken)
{ {

View File

@@ -10,7 +10,7 @@ using static PowerOCR.OSInterop;
namespace PowerOCR.Keyboard; namespace PowerOCR.Keyboard;
internal class GlobalKeyboardHook : IDisposable internal sealed class GlobalKeyboardHook : IDisposable
{ {
private IntPtr _windowsHookHandle; private IntPtr _windowsHookHandle;
private IntPtr _user32LibraryHandle; private IntPtr _user32LibraryHandle;
@@ -39,7 +39,7 @@ internal class GlobalKeyboardHook : IDisposable
internal event EventHandler<GlobalKeyboardHookEventArgs>? KeyboardPressed; internal event EventHandler<GlobalKeyboardHookEventArgs>? KeyboardPressed;
protected virtual void Dispose(bool disposing) public void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View File

@@ -7,7 +7,7 @@ using static PowerOCR.OSInterop;
namespace PowerOCR.Keyboard; namespace PowerOCR.Keyboard;
internal class GlobalKeyboardHookEventArgs : HandledEventArgs internal sealed class GlobalKeyboardHookEventArgs : HandledEventArgs
{ {
internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; } internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }

View File

@@ -35,7 +35,7 @@ public partial class OCROverlay : Window
private Point GetMousePos() => PointToScreen(Mouse.GetPosition(this)); private Point GetMousePos() => PointToScreen(Mouse.GetPosition(this));
private Language? selectedLanguage = null; private Language? selectedLanguage;
private MenuItem cancelMenuItem; private MenuItem cancelMenuItem;
private System.Windows.Forms.Screen? CurrentScreen private System.Windows.Forms.Screen? CurrentScreen
@@ -70,8 +70,8 @@ public partial class OCROverlay : Window
foreach (Language language in possibleOcrLanguages) foreach (Language language in possibleOcrLanguages)
{ {
MenuItem menuItem = new MenuItem() { Header = language.NativeName, Tag = language, IsCheckable = true }; MenuItem menuItem = new MenuItem() { Header = language.NativeName, Tag = language, IsCheckable = true };
menuItem.IsChecked = language.DisplayName.Equals(selectedLanguageName); menuItem.IsChecked = language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal);
if (language.DisplayName.Equals(selectedLanguageName)) if (language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal))
{ {
selectedLanguage = language; selectedLanguage = language;
} }

View File

@@ -7,6 +7,7 @@ using System.CommandLine;
using System.CommandLine.Invocation; using System.CommandLine.Invocation;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reactive.Concurrency; using System.Reactive.Concurrency;
@@ -255,7 +256,7 @@ namespace Awake
{ {
try try
{ {
DateTime expirationDateTime = DateTime.Parse(expireAt); DateTime expirationDateTime = DateTime.Parse(expireAt, CultureInfo.CurrentCulture);
if (expirationDateTime > DateTime.Now) if (expirationDateTime > DateTime.Now)
{ {
// We want to have a dedicated expirable keep-awake logic instead of // We want to have a dedicated expirable keep-awake logic instead of

View File

@@ -9,7 +9,7 @@ using Microsoft.PowerToys.Telemetry.Events;
namespace Awake.Telemetry namespace Awake.Telemetry
{ {
[EventData] [EventData]
internal class AwakeNoKeepAwakeEvent : EventBase, IEvent internal sealed class AwakeNoKeepAwakeEvent : EventBase, IEvent
{ {
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage; public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
} }

View File

@@ -246,9 +246,7 @@ namespace ColorPicker.ViewModels
new ColorFormatModel() new ColorFormatModel()
{ {
FormatName = ColorRepresentationType.HEX.ToString(), FormatName = ColorRepresentationType.HEX.ToString(),
#pragma warning disable CA1304 // Specify CultureInfo Convert = (Color color) => ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX.ToString()).ToLowerInvariant(),
Convert = (Color color) => ColorRepresentationHelper.GetStringRepresentationFromMediaColor(color, ColorRepresentationType.HEX.ToString()).ToLower(),
#pragma warning restore CA1304 // Specify CultureInfo
}); });
_allColorRepresentations.Add( _allColorRepresentations.Add(

View File

@@ -159,7 +159,7 @@ namespace FancyZonesEditor
public abstract void Move(int delta); public abstract void Move(int delta);
} }
private class SnappyHelperMagnetic : SnappyHelperBase private sealed class SnappyHelperMagnetic : SnappyHelperBase
{ {
private List<int> magnetZoneSizes; private List<int> magnetZoneSizes;
private int freePosition; private int freePosition;
@@ -220,7 +220,7 @@ namespace FancyZonesEditor
} }
} }
private class SnappyHelperNonMagnetic : SnappyHelperBase private sealed class SnappyHelperNonMagnetic : SnappyHelperBase
{ {
public SnappyHelperNonMagnetic(IList<Int32Rect> zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisOrigin, int screenAxisSize) public SnappyHelperNonMagnetic(IList<Int32Rect> zones, int zoneIndex, bool isX, ResizeMode mode, int screenAxisOrigin, int screenAxisSize)
: base(zones, zoneIndex, isX, mode, screenAxisOrigin, screenAxisSize) : base(zones, zoneIndex, isX, mode, screenAxisOrigin, screenAxisSize)

View File

@@ -8,7 +8,7 @@ using System.Windows.Controls;
namespace FancyZonesEditor.Controls namespace FancyZonesEditor.Controls
{ {
internal class CustomSliderAutomationPeer : SliderAutomationPeer internal sealed class CustomSliderAutomationPeer : SliderAutomationPeer
{ {
private string name = string.Empty; private string name = string.Empty;

View File

@@ -175,7 +175,7 @@ namespace FancyZonesEditor.Utils
} }
// custom-layouts.json // custom-layouts.json
private class CanvasInfoWrapper private sealed class CanvasInfoWrapper
{ {
public struct CanvasZoneWrapper public struct CanvasZoneWrapper
{ {
@@ -198,7 +198,7 @@ namespace FancyZonesEditor.Utils
} }
// custom-layouts.json // custom-layouts.json
private class GridInfoWrapper private sealed class GridInfoWrapper
{ {
public int Rows { get; set; } public int Rows { get; set; }

View File

@@ -9,7 +9,7 @@ using System.Windows.Interop;
namespace FancyZonesEditor.Utils namespace FancyZonesEditor.Utils
{ {
internal class NativeMethods internal sealed class NativeMethods
{ {
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex); private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

View File

@@ -75,7 +75,7 @@ namespace ImageResizer.Test
return raisedEvent; return raisedEvent;
} }
public class RaisedEvent<TArgs> public sealed class RaisedEvent<TArgs>
{ {
public RaisedEvent(object sender, TArgs args) public RaisedEvent(object sender, TArgs args)
{ {

View File

@@ -62,7 +62,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
return new Result return new Result
{ {
ContextData = result, ContextData = result,
Title = result.ToString(), Title = result.ToString(null),
IcoPath = _icon_path, IcoPath = _icon_path,
Score = 300, Score = 300,
SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.copy_to_clipboard, result.QuantityInfo.Name), SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.copy_to_clipboard, result.QuantityInfo.Name),

View File

@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces 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); private static readonly Regex WindowsPath = new Regex(@"^([a-zA-Z]:)", RegexOptions.Compiled);

View File

@@ -439,9 +439,9 @@ namespace Microsoft.Plugin.Program.Programs
paths.Add(path); paths.Add(path);
} }
if (_scaleFactors.ContainsKey(Package.Version)) if (_scaleFactors.TryGetValue(Package.Version, out List<int> factors))
{ {
foreach (var factor in _scaleFactors[Package.Version]) foreach (var factor in factors)
{ {
if (highContrast) if (highContrast)
{ {

View File

@@ -17,7 +17,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
/// <summary> /// <summary>
/// This class represents the informations for a network connection/interface /// This class represents the informations for a network connection/interface
/// </summary> /// </summary>
internal class NetworkConnectionProperties internal sealed class NetworkConnectionProperties
{ {
/// <summary> /// <summary>
/// Gets the name of the adapter /// Gets the name of the adapter

View File

@@ -4,7 +4,7 @@
namespace Microsoft.PowerToys.Run.Plugin.System.Components namespace Microsoft.PowerToys.Run.Plugin.System.Components
{ {
internal class SystemPluginContext internal sealed class SystemPluginContext
{ {
/// <summary> /// <summary>
/// Gets or sets the type of the result /// Gets or sets the type of the result

View File

@@ -9,7 +9,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
/// <summary> /// <summary>
/// A windows setting /// A windows setting
/// </summary> /// </summary>
internal class WindowsSetting internal sealed class WindowsSetting
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WindowsSetting"/> class. /// Initializes a new instance of the <see cref="WindowsSetting"/> class.

View File

@@ -10,7 +10,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
/// <summary> /// <summary>
/// A class that contain all possible windows settings /// A class that contain all possible windows settings
/// </summary> /// </summary>
internal class WindowsSettings internal sealed class WindowsSettings
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WindowsSettings"/> class with an empty settings list. /// Initializes a new instance of the <see cref="WindowsSettings"/> class with an empty settings list.

View File

@@ -9,7 +9,7 @@ using System.Windows.Controls;
namespace PowerLauncher namespace PowerLauncher
{ {
public class CustomSearchBox : TextBox public sealed class CustomSearchBox : TextBox
{ {
public List<UIElement> ControlledElements { get; } = new List<UIElement>(); public List<UIElement> ControlledElements { get; } = new List<UIElement>();
@@ -18,7 +18,7 @@ namespace PowerLauncher
return new AutoSuggestTextBoxAutomationPeer(this); return new AutoSuggestTextBoxAutomationPeer(this);
} }
internal class AutoSuggestTextBoxAutomationPeer : TextBoxAutomationPeer internal sealed class AutoSuggestTextBoxAutomationPeer : TextBoxAutomationPeer
{ {
public AutoSuggestTextBoxAutomationPeer(CustomSearchBox owner) public AutoSuggestTextBoxAutomationPeer(CustomSearchBox owner)
: base(owner) : base(owner)

View File

@@ -7,7 +7,7 @@ using Wox.Plugin;
namespace PowerLauncher.Helper namespace PowerLauncher.Helper
{ {
internal class KeyboardHelper internal sealed class KeyboardHelper
{ {
public static SpecialKeyState CheckModifiers() public static SpecialKeyState CheckModifiers()
{ {

View File

@@ -17,7 +17,7 @@ using Wox.Plugin.Logger;
namespace PowerLauncher namespace PowerLauncher
{ {
internal partial class ReportWindow internal sealed partial class ReportWindow
{ {
private static readonly IFileSystem FileSystem = new FileSystem(); private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IFile File = FileSystem.File; private static readonly IFile File = FileSystem.File;

View File

@@ -269,9 +269,9 @@ namespace PowerLauncher
var defaultOptions = defaultAdditionalOptions.ToDictionary(x => x.Key); var defaultOptions = defaultAdditionalOptions.ToDictionary(x => x.Key);
foreach (var option in additionalOptions) 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;
} }
} }

View File

@@ -154,9 +154,7 @@ namespace Wox.Infrastructure.Hotkey
if (CharKey != Key.None) if (CharKey != Key.None)
{ {
text += _specialSymbolDictionary.ContainsKey(CharKey) text += _specialSymbolDictionary.TryGetValue(CharKey, out string value) ? value : CharKey.ToString();
? _specialSymbolDictionary[CharKey]
: CharKey.ToString();
} }
else if (!string.IsNullOrEmpty(text)) else if (!string.IsNullOrEmpty(text))
{ {

View File

@@ -34,12 +34,7 @@ namespace Wox.Infrastructure.Image
enc.Frames.Add(bitmapFrame); enc.Frames.Add(bitmapFrame);
enc.Save(outStream); enc.Save(outStream);
var byteArray = outStream.GetBuffer(); var byteArray = outStream.GetBuffer();
return Convert.ToBase64String(SHA1.HashData(byteArray));
using (var sha1 = SHA1.Create())
{
var hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
return hash;
}
} }
} }
catch (System.Exception e) catch (System.Exception e)

View File

@@ -25,9 +25,9 @@ namespace Wox.Plugin.Common
public string GetLocalizedName(string path) public string GetLocalizedName(string path)
{ {
// Checking cache if path is already localized // 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; Guid shellItemType = ShellItemTypeConstants.ShellItemGuid;

View File

@@ -39,12 +39,8 @@ namespace Wox.Plugin
throw new ArgumentNullException(nameof(result)); 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) public void Add(Result result)
{ {

View File

@@ -14,7 +14,7 @@ namespace Wox.Test
public class WoxTest public class WoxTest
{ {
// A Dummy class to test that OnPropertyChanged() is called while we set the variable // 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; } public bool IsFunctionCalled { get; set; }

View File

@@ -2,9 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using PowerToys.PowerAccentKeyboardService; using PowerToys.PowerAccentKeyboardService;
using Windows.Globalization;
namespace PowerAccent.Core namespace PowerAccent.Core
{ {
@@ -42,7 +40,7 @@ namespace PowerAccent.Core
TK, TK,
} }
internal class Languages internal sealed class Languages
{ {
public static string[] GetDefaultLetterKey(LetterKey letter, Language lang) public static string[] GetDefaultLetterKey(LetterKey letter, Language lang)
{ {

View File

@@ -34,6 +34,7 @@ namespace PowerAccent.Core.Tools
return timestamp; 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) public void IncrementUsageFrequency(string character)
{ {
if (_characterUsageCounters.ContainsKey(character)) if (_characterUsageCounters.ContainsKey(character))

View File

@@ -17,7 +17,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
private Visibility _characterNameVisibility = Visibility.Visible; private Visibility _characterNameVisibility = Visibility.Visible;
private int _selectedIndex = 0; private int _selectedIndex;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;

View File

@@ -13,7 +13,7 @@ namespace PreviewHandlerCommonUnitTests
[TestClass] [TestClass]
public class FormHandlerControlTests public class FormHandlerControlTests
{ {
private class TestFormControl : FormHandlerControl private sealed class TestFormControl : FormHandlerControl
{ {
} }

View File

@@ -10,7 +10,7 @@ namespace PreviewHandlerCommon.ComInterop
/// <summary> /// <summary>
/// Interop methods /// Interop methods
/// </summary> /// </summary>
internal class NativeMethods internal sealed class NativeMethods
{ {
/// <summary> /// <summary>
/// Changes the parent window of the specified child window. /// Changes the parent window of the specified child window.

View File

@@ -73,7 +73,7 @@ namespace Common
} }
/// <inheritdoc /> /// <inheritdoc />
public void SetRect(Rectangle rect) public void SetRect(Rectangle windowBounds)
{ {
this.UpdateWindowBounds(parentHwnd); this.UpdateWindowBounds(parentHwnd);
} }

View File

@@ -60,7 +60,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
private bool FilterKeyboardEvents(KeyboardEvent ev) private bool FilterKeyboardEvents(KeyboardEvent ev)
{ {
#pragma warning disable CA2020 // Prevent from behavioral change
return _filterKeyboardEvent(ev.key, (UIntPtr)ev.dwExtraInfo); return _filterKeyboardEvent(ev.key, (UIntPtr)ev.dwExtraInfo);
#pragma warning restore CA2020 // Prevent from behavioral change
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)

View File

@@ -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 // mostly from https://stackoverflow.com/questions/58694837/system-text-json-merge-two-objects
// but with some update to prevent array item duplicates // 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 retoreFullPath = Path.Combine(appBasePath, relativePath);
var settingsToRestoreJson = GetExportVersion(backupRetoreSettings, currentFile.Key, currentFile.Value); 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 // 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)) 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 currentSettingsFileToBackup = GetExportVersion(backupRetoreSettings, currentFile.Key, currentFile.Value);
var doBackup = false; 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. // 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. // check to see if the new export version would be same as last export version.
if (JsonNormalizer.Normalize(currentSettingsFileToBackup) != JsonNormalizer.Normalize(lastSettingsFileDoc)) if (JsonNormalizer.Normalize(currentSettingsFileToBackup) != JsonNormalizer.Normalize(lastSettingsFileDoc))
@@ -989,7 +989,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// Class <c>JsonNormalizer</c> is a utility class to 'normalize' a JSON file so that it can be compared to another JSON file. /// Class <c>JsonNormalizer</c> 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. /// This really just means to fully sort it. This does not work for any JSON file where the order of the node is relevant.
/// </summary> /// </summary>
private class JsonNormalizer private sealed class JsonNormalizer
{ {
public static string Normalize(string json) public static string Normalize(string json)
{ {

View File

@@ -20,7 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
// Using Ordinal since this is used internally for a path // Using Ordinal since this is used internally for a path
private static readonly Expression<Func<string, bool>> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal); private static readonly Expression<Func<string, bool>> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
internal class MockSettingsRepository<T> : ISettingsRepository<T> internal sealed class MockSettingsRepository<T> : ISettingsRepository<T>
where T : ISettingsConfig, new() where T : ISettingsConfig, new()
{ {
private readonly ISettingsUtils _settingsUtils; private readonly ISettingsUtils _settingsUtils;

View File

@@ -100,7 +100,7 @@ namespace CommonLibTest
.Select(s => s[random.Next(s.Length)]).ToArray()); .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; public int TestInt { get; set; } = 100;

View File

@@ -14,7 +14,7 @@ namespace ViewModelTests
[TestClass] [TestClass]
public class PowerLauncherViewModelTest public class PowerLauncherViewModelTest
{ {
private class SendCallbackMock private sealed class SendCallbackMock
{ {
public int TimesSent { get; set; } public int TimesSent { get; set; }

View File

@@ -9,7 +9,7 @@ using Windows.ApplicationModel.Activation;
namespace Microsoft.PowerToys.Settings.UI.Activation namespace Microsoft.PowerToys.Settings.UI.Activation
{ {
internal class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs> internal sealed class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs>
{ {
private readonly Type navElement; private readonly Type navElement;

View File

@@ -163,8 +163,8 @@ namespace Microsoft.PowerToys.Settings.UI
if (containsFlyoutPosition) if (containsFlyoutPosition)
{ {
// get the flyout position arguments // get the flyout position arguments
int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x); _ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_x);
int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y); _ = int.TryParse(cmdArgs[currentArgumentIndex++], out flyout_y);
} }
RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () => RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>

View File

@@ -9,7 +9,7 @@ using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Helpers 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"); private static string _placementPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\settings-placement.json");

View File

@@ -25,7 +25,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
public sealed partial class OobeWhatsNew : Page public sealed partial class OobeWhatsNew : Page
{ {
// Contains information for a release. Used to deserialize release JSON info from GitHub. // Contains information for a release. Used to deserialize release JSON info from GitHub.
private class PowerToysReleaseInfo private sealed class PowerToysReleaseInfo
{ {
[JsonPropertyName("published_at")] [JsonPropertyName("published_at")]
public DateTimeOffset PublishedDate { get; set; } public DateTimeOffset PublishedDate { get; set; }

View File

@@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Services
{ {
// For more information on understanding and extending activation flow see // For more information on understanding and extending activation flow see
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md // https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
internal class ActivationService internal sealed class ActivationService
{ {
private readonly App app; private readonly App app;
private readonly Type defaultNavItem; private readonly Type defaultNavItem;

View File

@@ -241,7 +241,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
// skip entries with empty name or duplicated name, it should never occur // skip entries with empty name or duplicated name, it should never occur
string storedName = storedColorFormat.Key; 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; continue;
} }

View File

@@ -36,7 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
} }
public Action<FlyoutMenuItem> EnabledChangedCallback { get; set; } = null; public Action<FlyoutMenuItem> EnabledChangedCallback { get; set; }
public bool Visible public bool Visible
{ {

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Timers; using System.Timers;
@@ -9,8 +10,11 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout 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; } public bool CanHide { get; set; }
private bool _windows10; private bool _windows10;
@@ -28,29 +32,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
} }
} }
private Timer hideTimer;
public FlyoutViewModel() public FlyoutViewModel()
{ {
CanHide = true; CanHide = true;
hideTimer = new Timer(); _hideTimer = new Timer();
hideTimer.Elapsed += HideTimer_Elapsed; _hideTimer.Elapsed += HideTimer_Elapsed;
hideTimer.Interval = 1000; _hideTimer.Interval = 1000;
hideTimer.Enabled = false; _hideTimer.Enabled = false;
_windows10 = !Helper.Windows11(); _windows10 = !Helper.Windows11();
} }
private void HideTimer_Elapsed(object sender, ElapsedEventArgs e) private void HideTimer_Elapsed(object sender, ElapsedEventArgs e)
{ {
CanHide = true; CanHide = true;
hideTimer.Stop(); _hideTimer.Stop();
} }
internal void DisableHiding() internal void DisableHiding()
{ {
CanHide = false; CanHide = false;
hideTimer.Stop(); _hideTimer.Stop();
hideTimer.Start(); _hideTimer.Start();
} }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@@ -59,5 +61,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 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;
}
}
}
} }
} }

View File

@@ -178,12 +178,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
AvailableLanguages.Clear(); AvailableLanguages.Clear();
foreach (Language language in possibleOcrLanguages) 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; 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; systemLanguageIndex = AvailableLanguages.Count;
} }

View File

@@ -100,7 +100,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
string csMessage = csIpcMessage.ToJsonString(); string csMessage = csIpcMessage.ToJsonString();
string outMessage = outIpcMessage.ToJsonString(); string outMessage = outIpcMessage.ToJsonString();
if (!csMessage.Equals(outMessage)) if (!csMessage.Equals(outMessage, StringComparison.Ordinal))
{ {
Logger.LogInfo($"Saved Awake settings from Awake page."); Logger.LogInfo($"Saved Awake settings from Awake page.");
_sendConfigMsg(outMessage); _sendConfigMsg(outMessage);

View File

@@ -333,7 +333,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
IJsonValue whatToShowJson; IJsonValue whatToShowJson;
if (json.TryGetValue("ShowYourself", out 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; POINT? p = null;
@@ -351,7 +351,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
OpenFlyoutCallback(p); 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(); OpenMainWindowCallback();
} }