From d421f83533c1b460a1f0d46a7715eca0d4f52e70 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Sun, 18 Feb 2024 20:21:41 +0800 Subject: [PATCH] fix: resolves CA1859 error --- .../Middlewares/ProjectFileOptionsConfigureMiddleware.cs | 7 +++++-- tests/IntegrationTest/NuGetReferenceResolverTest.cs | 2 ++ tests/UnitTest/ReferenceTest.cs | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/dotnet-exec/Services/Middlewares/ProjectFileOptionsConfigureMiddleware.cs b/src/dotnet-exec/Services/Middlewares/ProjectFileOptionsConfigureMiddleware.cs index ee49f47..8f3738e 100644 --- a/src/dotnet-exec/Services/Middlewares/ProjectFileOptionsConfigureMiddleware.cs +++ b/src/dotnet-exec/Services/Middlewares/ProjectFileOptionsConfigureMiddleware.cs @@ -108,9 +108,10 @@ public async Task InvokeAsync(ExecOptions options, Func next) packageVersion = newPackageVersion; } } - - IReference reference = new NuGetReference(packageId, packageVersion); +#pragma warning disable CA1859 // Use concrete types when possible for improved performance + IReference reference = new NuGetReference(packageId, packageVersion); options.References.Add(reference.ReferenceWithSchema); +#pragma warning restore CA1859 // Use concrete types when possible for improved performance } if (File.Exists(projectPath)) @@ -127,8 +128,10 @@ public async Task InvokeAsync(ExecOptions options, Func next) if (!File.Exists(referenceProjectPath)) continue; +#pragma warning disable CA1859 // Use concrete types when possible for improved performance IReference projectReference = new ProjectReference(referenceProjectFullPath); options.References.Add(projectReference.ReferenceWithSchema); +#pragma warning restore CA1859 // Use concrete types when possible for improved performance } } diff --git a/tests/IntegrationTest/NuGetReferenceResolverTest.cs b/tests/IntegrationTest/NuGetReferenceResolverTest.cs index deee60c..a85c437 100644 --- a/tests/IntegrationTest/NuGetReferenceResolverTest.cs +++ b/tests/IntegrationTest/NuGetReferenceResolverTest.cs @@ -22,8 +22,10 @@ public async Task Resolve() [Fact] public async Task ResolveReference() { +#pragma warning disable CA1859 // Use concrete types when possible for improved performance IReference reference = new NuGetReference("WeihanLi.Common", "1.0.60"); Assert.Equal($"nuget: {reference.Reference}", reference.ReferenceWithSchema); +#pragma warning restore CA1859 // Use concrete types when possible for improved performance var references = await _resolver.Resolve(reference.Reference, ExecOptions.DefaultTargetFramework); Assert.NotNull(references); diff --git a/tests/UnitTest/ReferenceTest.cs b/tests/UnitTest/ReferenceTest.cs index 7b2f64c..b7cbb63 100644 --- a/tests/UnitTest/ReferenceTest.cs +++ b/tests/UnitTest/ReferenceTest.cs @@ -11,17 +11,21 @@ public class ReferenceTest [Fact] public void FileReferenceTypeTest() { - IReference reference = new FileReference("ReferenceResolver.dll"); +#pragma warning disable CA1859 // Use concrete types when possible for improved performance + IReference reference = new FileReference("ReferenceResolver.dll"); Assert.Equal(ReferenceType.LocalFile, reference.ReferenceType); Assert.Equal($"file: {reference.Reference}", reference.ReferenceWithSchema); +#pragma warning restore CA1859 // Use concrete types when possible for improved performance } [Fact] public void NuGetReferenceTypeTest() { +#pragma warning disable CA1859 // Use concrete types when possible for improved performance IReference reference = new NuGetReference("ReferenceResolver", "1.0.0"); Assert.Equal(ReferenceType.NuGetPackage, reference.ReferenceType); Assert.Equal($"nuget: {reference.Reference}", reference.ReferenceWithSchema); +#pragma warning restore CA1859 // Use concrete types when possible for improved performance } [Fact]