-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix simple factory for generic type markers
- Loading branch information
1 parent
a7ec131
commit 6aebe3b
Showing
5 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace Pure.DI.Core; | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
internal class FullyQualifiedNameRewriter(SemanticModel semanticModel): CSharpSyntaxRewriter | ||
{ | ||
public static readonly SymbolDisplayFormat FullTypeNameFormat = | ||
new( | ||
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, | ||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, | ||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, | ||
miscellaneousOptions: | ||
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | | ||
SymbolDisplayMiscellaneousOptions.UseSpecialTypes); | ||
|
||
public override SyntaxNode? VisitQualifiedName(QualifiedNameSyntax node) | ||
{ | ||
if (semanticModel.GetSymbolInfo(node).Symbol is not ITypeSymbol type) | ||
{ | ||
return base.VisitQualifiedName(node); | ||
} | ||
|
||
var typeName = type.ToDisplayString(NullableFlowState.None, FullTypeNameFormat); | ||
return SyntaxFactory.ParseTypeName(typeName); | ||
} | ||
|
||
public override SyntaxNode? VisitGenericName(GenericNameSyntax node) | ||
{ | ||
if (semanticModel.GetSymbolInfo(node).Symbol is not ITypeSymbol type) | ||
{ | ||
return base.VisitGenericName(node); | ||
} | ||
|
||
var typeName = type.ToDisplayString(NullableFlowState.None, FullTypeNameFormat); | ||
return SyntaxFactory.ParseTypeName(typeName); | ||
} | ||
|
||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node) | ||
{ | ||
if (semanticModel.GetSymbolInfo(node).Symbol is not ITypeSymbol type) | ||
{ | ||
return base.VisitIdentifierName(node); | ||
} | ||
|
||
var typeName = type.ToDisplayString(NullableFlowState.None, FullTypeNameFormat); | ||
return SyntaxFactory.ParseTypeName(typeName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters