Skip to content

Commit

Permalink
Merge pull request #86 from ltrzesniewski/alias-any-type
Browse files Browse the repository at this point in the history
Support aliases for any type
  • Loading branch information
KirillOsenkov authored Dec 6, 2024
2 parents d892b85 + 73dbffa commit ee17b3b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/roslynquoter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ bld/
# Roslyn cache directories
*.vs/

# Rider
.idea/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down
4 changes: 2 additions & 2 deletions src/Quoter.Tests/Quoter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime;build;native;contentFiles;analyzers</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 7 additions & 0 deletions src/Quoter.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 16 additions & 3 deletions src/Quoter/Quoter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Quoter/Quoter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.12.0" />
</ItemGroup>

</Project>

0 comments on commit ee17b3b

Please sign in to comment.