Skip to content

Commit 737054c

Browse files
committed
refactor: Apply .NET 8 Languages
1 parent 810d73a commit 737054c

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/UnityBuildRunner.Core/SimpleConsoleLogger.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.DependencyInjection.Extensions;
33
using Microsoft.Extensions.Logging;
4-
using System;
54

65
namespace UnityBuildRunner.Core;
76

@@ -30,7 +29,7 @@ public SimpleConsoleLogger()
3029
{
3130
}
3231

33-
public IDisposable BeginScope<TState>(TState state)
32+
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
3433
{
3534
return NullDisposable.Instance;
3635
}
@@ -42,7 +41,7 @@ public bool IsEnabled(LogLevel logLevel)
4241

4342
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
4443
{
45-
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
44+
ArgumentNullException.ThrowIfNull(formatter);
4645

4746
var msg = formatter(state, exception);
4847

src/UnityBuildRunner/Program.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
using Microsoft.Extensions.Logging;
2-
using System;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using UnityBuildRunner.Core;
63

74
var builder = ConsoleApp.CreateBuilder(args);
85
var app = builder.Build();
96
app.AddCommands<UnityBuildRunnerCommand>();
107
app.Run();
118

12-
public class UnityBuildRunnerCommand : ConsoleAppBase
9+
public class UnityBuildRunnerCommand(ILogger<UnityBuildRunnerCommand> logger) : ConsoleAppBase
1310
{
1411
private const string DefaultTimeout = "02:00:00"; // 2 hours
1512

16-
private readonly ILogger<UnityBuildRunnerCommand> logger;
17-
private readonly TimeSpan timeoutDefault;
18-
19-
public UnityBuildRunnerCommand(ILogger<UnityBuildRunnerCommand> logger)
20-
{
21-
this.logger = logger;
22-
timeoutDefault = TimeSpan.Parse(DefaultTimeout);
23-
}
13+
private readonly TimeSpan timeoutDefault = TimeSpan.Parse(DefaultTimeout);
2414

2515
[RootCommand]
2616
public async Task<int> Run([Option("--unity-path", "Full Path to the Unity executable, leave empty when use 'UnityPath' Environment variables instead.")] string unityPath = "", [Option("--timeout", "Timeout for Unity Build.")] string timeout = DefaultTimeout)
2717
{
2818
var arguments = Context.Arguments
29-
.Except(new[] { "--timeout", timeout });
19+
.Except(["--timeout", timeout]);
3020
if (!string.IsNullOrEmpty(unityPath))
3121
{
32-
arguments = arguments.Except(new[] { "--unity-path", unityPath });
22+
arguments = arguments.Except(["--unity-path", unityPath]);
3323
}
3424
var args = arguments?.ToArray();
3525

36-
if (args is null || !args.Any())
26+
if (args is null || args.Length == 0)
3727
{
38-
throw new ArgumentOutOfRangeException($"No valid argument found, exiting. You have specified arguments: {string.Join(" ", args ?? Array.Empty<string>())}");
28+
throw new ArgumentOutOfRangeException($"No valid argument found, exiting. You have specified arguments: {string.Join(" ", args ?? [])}");
3929
}
4030

4131
// build

tests/UnityBuildRunner.Core.Tests/UnityBuildRunner.Core.Tests.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="GitHubActionsTestLogger" />
9-
<PackageReference Include="coverlet.msbuild" />
8+
<PackageReference Include="GitHubActionsTestLogger">
9+
<PrivateAssets>all</PrivateAssets>
10+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
11+
</PackageReference>
12+
<PackageReference Include="coverlet.msbuild">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
1016
<PackageReference Include="FluentAssertions" />
1117
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1218
<PackageReference Include="xunit" />
13-
<PackageReference Include="xunit.runner.visualstudio" />
19+
<PackageReference Include="xunit.runner.visualstudio">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
1423
</ItemGroup>
1524

1625
<ItemGroup>

0 commit comments

Comments
 (0)