Skip to content

Commit

Permalink
Use .NET 8 SDK, C# 12, Central Package Management and add net8.0 target
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZidar committed Nov 19, 2023
1 parent ed0ecc2 commit 841cd8b
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 39 deletions.
16 changes: 14 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions TinyHotKey.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
Expand Down
6 changes: 6 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
3 changes: 2 additions & 1 deletion samples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PropertyGroup>
<DebugType>embedded</DebugType>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>All</AnalysisMode>
<AnalysisLevel>7.0</AnalysisLevel>
<AnalysisLevel>8.0</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 2 additions & 10 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PropertyGroup>
<DebugType>embedded</DebugType>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -24,7 +24,7 @@
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<AnalysisMode>All</AnalysisMode>
<AnalysisLevel>7.0</AnalysisLevel>
<AnalysisLevel>8.0</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
Expand All @@ -33,12 +33,4 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Roslynator.Analyzers" Version="4.6.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(EnableSourceLink)' == 'true'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="Roslynator.Analyzers" Version="4.6.2" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/TinyHotKey/ITinyHotKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public static class TinyHotKeyExtensions
/// <exception cref="InvalidOperationException">Thrown when the hotkey combination could not be registered.</exception>
public static ITinyHotKeyRegistration RegisterHotKeyOrThrow(this ITinyHotKey tinyHotKey, Modifier modifiers, Key key, Func<Task> callback)
{
#if NET
ArgumentNullException.ThrowIfNull(tinyHotKey);
#else
if (tinyHotKey is null)
throw new ArgumentNullException(nameof(tinyHotKey));
#endif

var registration = tinyHotKey.RegisterHotKey(modifiers, key, callback);

Expand Down
6 changes: 3 additions & 3 deletions src/TinyHotKey/TinyHotKey.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<IsTrimmable>true</IsTrimmable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/TinyHotKey/TinyHotKeyInstance.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
29 changes: 12 additions & 17 deletions src/TinyHotKey/TinyHotKeyRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,23 @@ public void Dispose()
}
}

public sealed class TinyHotKeyRegistration : ITinyHotKeyRegistration
public sealed class TinyHotKeyRegistration(
nuint id,
Modifier modifiers,
Key key,
Func<Task> callback,
Action<TinyHotKeyRegistration> unregister
)
: ITinyHotKeyRegistration
{
public nuint Id { get; }
public Modifier Modifiers { get; }
public Key Key { get; }
public Func<Task> Callback { get; }
public nuint Id { get; } = id;
public Modifier Modifiers { get; } = modifiers;
public Key Key { get; } = key;
public Func<Task> Callback { get; } = callback;
public bool IsRegistered { get; } = true;

private readonly Action<TinyHotKeyRegistration> unregister;

private bool disposed;

public TinyHotKeyRegistration(nuint id, Modifier modifiers, Key key, Func<Task> callback, Action<TinyHotKeyRegistration> unregister)
{
Id = id;
Modifiers = modifiers;
Key = key;
Callback = callback;

this.unregister = unregister;
}

public void Dispose()
{
if (disposed)
Expand Down
4 changes: 2 additions & 2 deletions src/TinyHotKey/TinyHotKeyWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TinyHotKeyRegistration> registrations = new();
private readonly List<TinyHotKeyRegistration> registrations = [];
private readonly WndProc wndProcDelegate;

private ushort atom;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void Dispose()

lock (registrationLock)
{
registrationsToDispose = registrations.ToArray();
registrationsToDispose = [.. registrations];
}

// Dispose any left over registrations
Expand Down

0 comments on commit 841cd8b

Please sign in to comment.