Skip to content

Commit ee17b3b

Browse files
Merge pull request #86 from ltrzesniewski/alias-any-type
Support aliases for any type
2 parents d892b85 + 73dbffa commit ee17b3b

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

.github/workflows/roslynquoter.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
build:
1414
runs-on: windows-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v1
18+
uses: actions/setup-dotnet@v4
1919
with:
2020
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
2121
- name: Restore
@@ -27,7 +27,7 @@ jobs:
2727
- name: Publish
2828
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
2929
- name: Publish Artifacts
30-
uses: actions/upload-artifact@v1.0.0
30+
uses: actions/upload-artifact@v4
3131
with:
3232
name: webapp
3333
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
@@ -36,7 +36,7 @@ jobs:
3636
needs: build
3737
steps:
3838
- name: Download artifact from build job
39-
uses: actions/download-artifact@v4.1.7
39+
uses: actions/download-artifact@v4
4040
with:
4141
name: webapp
4242
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ bld/
2121
# Roslyn cache directories
2222
*.vs/
2323

24+
# Rider
25+
.idea/
26+
2427
# MSTest test Results
2528
[Tt]est[Rr]esult*/
2629
[Bb]uild[Ll]og.*

src/Quoter.Tests/Quoter.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="xunit" Version="2.4.2" />
10-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
9+
<PackageReference Include="xunit" Version="2.9.2" />
10+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime;build;native;contentFiles;analyzers</IncludeAssets>
1313
</PackageReference>

src/Quoter.Tests/Tests.cs

+7
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,13 @@ public void TestRecordStruct()
867867
nodeKind: NodeKind.MemberDeclaration);
868868
}
869869

870+
[Fact]
871+
public void TestIssue85()
872+
{
873+
Test("using Foo = object;");
874+
Test("using Foo = (int foo, int bar);");
875+
}
876+
870877
private void Test(
871878
string sourceText,
872879
string expected,

src/Quoter/Quoter.cs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,25 @@ private MethodInfo PickFactoryMethodToCreateNode(SyntaxNode node)
10441044
return candidates.First();
10451045
}
10461046

1047-
var usingDirectiveSyntax = node as UsingDirectiveSyntax;
1048-
if (usingDirectiveSyntax != null)
1047+
if (node is UsingDirectiveSyntax usingDirectiveSyntax)
10491048
{
10501049
if (usingDirectiveSyntax.Alias == null)
10511050
{
1052-
candidates = candidates.Where(m => m.ToString() != "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)");
1051+
const string signatureWithNameSyntax = "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)";
1052+
const string signatureWithTypeSyntax = "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameEqualsSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax)";
1053+
1054+
candidates = candidates.Where(m => m.ToString() is not (signatureWithNameSyntax or signatureWithTypeSyntax));
1055+
}
1056+
else
1057+
{
1058+
var preferredSignature = usingDirectiveSyntax.NamespaceOrType is NameSyntax
1059+
? "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax)"
1060+
: "Microsoft.CodeAnalysis.CSharp.Syntax.UsingDirectiveSyntax UsingDirective(Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax)";
1061+
1062+
if (candidates.FirstOrDefault(m => m.ToString() == preferredSignature) is { } preferredMethod)
1063+
{
1064+
return preferredMethod;
1065+
}
10531066
}
10541067
}
10551068

src/Quoter/Quoter.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
29+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.12.0" />
3030
</ItemGroup>
3131

3232
</Project>

0 commit comments

Comments
 (0)