Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 450c74f

Browse files
authored
Merge pull request #35 from episerver/user/jb/issue-34
Changed code to handle qualified type names
2 parents 647d2fc + 098c600 commit 450c74f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/EpiSourceUpdater/EpiClassReplacementsCodeFixProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
6363
private static async Task<Document> ReplaceClassesAsync(Document document, BaseTypeSyntax localDeclaration, string newIdentifier, CancellationToken cancellationToken)
6464
{
6565
var baseType = localDeclaration;
66-
var genericName = (SimpleNameSyntax)baseType.Type;
67-
68-
var newnode = genericName.WithIdentifier(SyntaxFactory.Identifier(newIdentifier));
66+
NameSyntax newnode = null;
67+
if (baseType.Type is SimpleNameSyntax simpleNameSyntax)
68+
{
69+
newnode = simpleNameSyntax.WithIdentifier(SyntaxFactory.Identifier(newIdentifier));
70+
}
71+
else if (baseType.Type is QualifiedNameSyntax qualifiedNameSyntax)
72+
{
73+
newnode = qualifiedNameSyntax.WithRight(qualifiedNameSyntax.Right.WithIdentifier(SyntaxFactory.Identifier(newIdentifier)));
74+
}
6975

7076
var syntaxTree = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
7177

72-
var newRoot = syntaxTree!.ReplaceNode(genericName, newnode);
78+
var newRoot = syntaxTree!.ReplaceNode(baseType.Type, newnode);
7379
return document.WithSyntaxRoot(newRoot);
7480
}
7581
}

src/EpiSourceUpdater/EpiSubTypeAnalyzer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace Epi.Source.Updater
1414
public abstract class EpiSubTypeAnalyzer : DiagnosticAnalyzer
1515
{
1616
private readonly string[] _baseTypes;
17-
private readonly bool _genericType;
1817

1918
public EpiSubTypeAnalyzer(params string[] baseTypes)
2019
{
@@ -37,6 +36,13 @@ protected bool IsSubType(ClassDeclarationSyntax classDirective)
3736
return true;
3837
}
3938
}
39+
else if (baseType.Type is QualifiedNameSyntax qualifiedNameSyntax)
40+
{
41+
if (_baseTypes.Contains(qualifiedNameSyntax.Right.Identifier.Text, StringComparer.OrdinalIgnoreCase))
42+
{
43+
return true;
44+
}
45+
}
4046
}
4147

4248
return false;

0 commit comments

Comments
 (0)