diff --git a/.editorconfig b/.editorconfig index bb8567a..12babcb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,14 +1,14 @@ root = true # Steamcore .NET library editorconfig -# dotnet_library_editorconfig_version = 14 +# dotnet_library_editorconfig_version = 15 [*] charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true -[*.{csproj,props,targets}] +[*.{config,csproj,props,targets}] indent_style = space indent_size = 2 @@ -176,6 +176,9 @@ dotnet_diagnostic.IDE0007.severity = suggestion # IDE0008: Use explicit type instead of 'var' dotnet_diagnostic.IDE0008.severity = none +# IDE0028: Use collection initializers +dotnet_diagnostic.IDE0028.severity = warning + # IDE0035: Remove unreachable code dotnet_diagnostic.IDE0035.severity = warning @@ -191,6 +194,15 @@ dotnet_diagnostic.IDE0079.severity = warning # IDE0080: Remove unnecessary suppression operator dotnet_diagnostic.IDE0080.severity = warning +# IDE0300: Collection initialization can be simplified +dotnet_diagnostic.IDE0300.severity = warning + +# IDE0301: Collection initialization can be simplified +dotnet_diagnostic.IDE0301.severity = warning + +# IDE0305: Collection initialization can be simplified +dotnet_diagnostic.IDE0305.severity = warning + # RCS1018: Add default access modifier dotnet_diagnostic.RCS1018.severity = warning diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36469eb..8f6edfd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' dotnet-quality: 'ga' - name: Restore dependencies diff --git a/TinyHotKey.sln b/TinyHotKey.sln index 2f0c6bc..447bdb8 100644 --- a/TinyHotKey.sln +++ b/TinyHotKey.sln @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{10D97319-62DA-4030-987A-848145DE0477}" ProjectSection(SolutionItems) = preProject src\Directory.Build.props = src\Directory.Build.props + src\Directory.Packages.props = src\Directory.Packages.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TinyHotKey", "src\TinyHotKey\TinyHotKey.csproj", "{E82144AC-E66C-4DB1-B16A-37DEB9F3C6A5}" diff --git a/global.json b/global.json index f5cfe25..b7e3357 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.100", + "version": "8.0.100", "allowPrerelease": false, "rollForward": "latestFeature" } diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..f17d758 --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/ConsoleApp/ConsoleApp.csproj b/samples/ConsoleApp/ConsoleApp.csproj index 9953aec..9b1904a 100644 --- a/samples/ConsoleApp/ConsoleApp.csproj +++ b/samples/ConsoleApp/ConsoleApp.csproj @@ -2,7 +2,8 @@ Exe - net7.0-windows + net8.0-windows + true diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 1b0ec45..7778783 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -8,13 +8,13 @@ embedded enable - 11.0 + 12.0 true All - 7.0 + 8.0 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9835bb5..bb6af7d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -15,7 +15,7 @@ embedded enable - 11.0 + 12.0 enable @@ -24,7 +24,7 @@ true true All - 7.0 + 8.0 @@ -33,12 +33,4 @@ - - - - - - - - diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..4772003 --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,16 @@ + + + + true + + + + + + + + + + + + diff --git a/src/TinyHotKey/ITinyHotKey.cs b/src/TinyHotKey/ITinyHotKey.cs index 9994da3..63a6457 100644 --- a/src/TinyHotKey/ITinyHotKey.cs +++ b/src/TinyHotKey/ITinyHotKey.cs @@ -36,8 +36,12 @@ public static class TinyHotKeyExtensions /// Thrown when the hotkey combination could not be registered. public static ITinyHotKeyRegistration RegisterHotKeyOrThrow(this ITinyHotKey tinyHotKey, Modifier modifiers, Key key, Func callback) { +#if NET + ArgumentNullException.ThrowIfNull(tinyHotKey); +#else if (tinyHotKey is null) throw new ArgumentNullException(nameof(tinyHotKey)); +#endif var registration = tinyHotKey.RegisterHotKey(modifiers, key, callback); diff --git a/src/TinyHotKey/TinyHotKey.csproj b/src/TinyHotKey/TinyHotKey.csproj index ace2de6..b005cd1 100644 --- a/src/TinyHotKey/TinyHotKey.csproj +++ b/src/TinyHotKey/TinyHotKey.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net6.0;net7.0 + netstandard2.0;net6.0;net7.0;net8.0 true true README.md @@ -12,8 +12,8 @@ - - + + diff --git a/src/TinyHotKey/TinyHotKeyInstance.cs b/src/TinyHotKey/TinyHotKeyInstance.cs index a8cf517..d015b07 100644 --- a/src/TinyHotKey/TinyHotKeyInstance.cs +++ b/src/TinyHotKey/TinyHotKeyInstance.cs @@ -1,9 +1,11 @@ +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; namespace TinyHotKey; public sealed class TinyHotKeyInstance : ITinyHotKey, IDisposable { + [SuppressMessage("Performance", "CA1859:Use concrete types when possible for improved performance", Justification = "This is intentionally using the interface")] private readonly ITinyHotKey platformInstance; private bool disposed; diff --git a/src/TinyHotKey/TinyHotKeyRegistration.cs b/src/TinyHotKey/TinyHotKeyRegistration.cs index c6982d5..1736ecd 100644 --- a/src/TinyHotKey/TinyHotKeyRegistration.cs +++ b/src/TinyHotKey/TinyHotKeyRegistration.cs @@ -23,28 +23,23 @@ public void Dispose() } } -public sealed class TinyHotKeyRegistration : ITinyHotKeyRegistration +public sealed class TinyHotKeyRegistration( + nuint id, + Modifier modifiers, + Key key, + Func callback, + Action unregister +) + : ITinyHotKeyRegistration { - public nuint Id { get; } - public Modifier Modifiers { get; } - public Key Key { get; } - public Func Callback { get; } + public nuint Id { get; } = id; + public Modifier Modifiers { get; } = modifiers; + public Key Key { get; } = key; + public Func Callback { get; } = callback; public bool IsRegistered { get; } = true; - private readonly Action unregister; - private bool disposed; - public TinyHotKeyRegistration(nuint id, Modifier modifiers, Key key, Func callback, Action unregister) - { - Id = id; - Modifiers = modifiers; - Key = key; - Callback = callback; - - this.unregister = unregister; - } - public void Dispose() { if (disposed) diff --git a/src/TinyHotKey/TinyHotKeyWindows.cs b/src/TinyHotKey/TinyHotKeyWindows.cs index e8dbf48..0fee276 100644 --- a/src/TinyHotKey/TinyHotKeyWindows.cs +++ b/src/TinyHotKey/TinyHotKeyWindows.cs @@ -26,7 +26,7 @@ internal sealed partial class TinyHotKeyWindows : ITinyHotKey, IDisposable private readonly AutoResetEvent messageLoopDone = new(false); private readonly ILogger? logger; private readonly object registrationLock = new(); - private readonly List registrations = new(); + private readonly List registrations = []; private readonly WndProc wndProcDelegate; private ushort atom; @@ -86,7 +86,7 @@ public void Dispose() lock (registrationLock) { - registrationsToDispose = registrations.ToArray(); + registrationsToDispose = [.. registrations]; } // Dispose any left over registrations