Use latest C# features

This commit is contained in:
Tyrrrz
2024-01-12 00:10:27 +02:00
parent 76e8d47e03
commit 6aa72e45e8
30 changed files with 186 additions and 390 deletions

View File

@@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.5" />
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.4.5" />
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.5" PrivateAssets="all" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="all" />

View File

@@ -23,7 +23,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
[CommandOption("foo", Validators = new[] { typeof(MyValidator) })]
public string? Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;
@@ -48,7 +48,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
[CommandOption("foo", Validators = new[] { typeof(MyValidator) })]
public string? Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;
@@ -73,7 +73,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
[CommandOption("foo", Validators = new[] { typeof(MyValidator) })]
public string? Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;

View File

@@ -23,7 +23,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
[CommandParameter(0, Validators = new[] { typeof(MyValidator) })]
public required string Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;
@@ -48,7 +48,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
[CommandParameter(0, Validators = new[] { typeof(MyValidator) })]
public required string Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;
@@ -73,7 +73,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs
[Command]
public class MyCommand : ICommand
{
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
[CommandParameter(0, Validators = new[] { typeof(MyValidator) })]
public required string Foo { get; init; }
public ValueTask ExecuteAsync(IConsole console) => default;

View File

@@ -47,14 +47,14 @@ internal class AnalyzerAssertions(DiagnosticAnalyzer analyzer)
// Parse the source code
var ast = SyntaxFactory.ParseSyntaxTree(
SourceText.From(sourceCodeWithUsings),
CSharpParseOptions.Default
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)
);
// Compile the code to IL
var compilation = CSharpCompilation.Create(
"CliFxTests_DynamicAssembly_" + Guid.NewGuid(),
new[] { ast },
Net70
[ast],
Net80
.References
.All
.Append(MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location)),