From 80e19881656ed14332173d919913d9efb685d46b Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Fri, 6 Dec 2024 18:20:17 +0100 Subject: [PATCH 1/2] Update GitHub Actions tags Previous tags were deprecated --- .github/workflows/roslynquoter.yml | 8 ++++---- .gitignore | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/roslynquoter.yml b/.github/workflows/roslynquoter.yml index 07f2ad0..6d30906 100644 --- a/.github/workflows/roslynquoter.yml +++ b/.github/workflows/roslynquoter.yml @@ -13,9 +13,9 @@ jobs: build: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup .NET Core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_CORE_VERSION }} - name: Restore @@ -27,7 +27,7 @@ jobs: - name: Publish run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}" - name: Publish Artifacts - uses: actions/upload-artifact@v1.0.0 + uses: actions/upload-artifact@v4 with: name: webapp path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} @@ -36,7 +36,7 @@ jobs: needs: build steps: - name: Download artifact from build job - uses: actions/download-artifact@v4.1.7 + uses: actions/download-artifact@v4 with: name: webapp path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} diff --git a/.gitignore b/.gitignore index c89f7f3..371e625 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ bld/ # Roslyn cache directories *.vs/ +# Rider +.idea/ + # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* From 73dbffa7e4fc259bf21e3cfe0739d3aedb6e9331 Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Fri, 6 Dec 2024 20:25:55 +0100 Subject: [PATCH 2/2] Support aliases for any type --- src/Quoter.Tests/Quoter.Tests.csproj | 4 ++-- src/Quoter.Tests/Tests.cs | 7 +++++++ src/Quoter/Quoter.cs | 19 ++++++++++++++++--- src/Quoter/Quoter.csproj | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Quoter.Tests/Quoter.Tests.csproj b/src/Quoter.Tests/Quoter.Tests.csproj index fd945ff..87a1028 100644 --- a/src/Quoter.Tests/Quoter.Tests.csproj +++ b/src/Quoter.Tests/Quoter.Tests.csproj @@ -6,8 +6,8 @@ - - + + all runtime;build;native;contentFiles;analyzers diff --git a/src/Quoter.Tests/Tests.cs b/src/Quoter.Tests/Tests.cs index 8850e65..0768cfa 100644 --- a/src/Quoter.Tests/Tests.cs +++ b/src/Quoter.Tests/Tests.cs @@ -867,6 +867,13 @@ public void TestRecordStruct() nodeKind: NodeKind.MemberDeclaration); } + [Fact] + public void TestIssue85() + { + Test("using Foo = object;"); + Test("using Foo = (int foo, int bar);"); + } + private void Test( string sourceText, string expected, diff --git a/src/Quoter/Quoter.cs b/src/Quoter/Quoter.cs index 44a01bb..6dd8255 100644 --- a/src/Quoter/Quoter.cs +++ b/src/Quoter/Quoter.cs @@ -1044,12 +1044,25 @@ private MethodInfo PickFactoryMethodToCreateNode(SyntaxNode node) return candidates.First(); } - var usingDirectiveSyntax = node as UsingDirectiveSyntax; - if (usingDirectiveSyntax != null) + if (node is UsingDirectiveSyntax usingDirectiveSyntax) { if (usingDirectiveSyntax.Alias == null) { - candidates = candidates.Where(m => m.ToString() != "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)"); + const string signatureWithNameSyntax = "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)"; + const string signatureWithTypeSyntax = "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax)"; + + candidates = candidates.Where(m => m.ToString() is not (signatureWithNameSyntax or signatureWithTypeSyntax)); + } + else + { + var preferredSignature = usingDirectiveSyntax.NamespaceOrType is NameSyntax + ? "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)" + : "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax)"; + + if (candidates.FirstOrDefault(m => m.ToString() == preferredSignature) is { } preferredMethod) + { + return preferredMethod; + } } } diff --git a/src/Quoter/Quoter.csproj b/src/Quoter/Quoter.csproj index 4ea0d2f..55574db 100644 --- a/src/Quoter/Quoter.csproj +++ b/src/Quoter/Quoter.csproj @@ -26,7 +26,7 @@ - + \ No newline at end of file