Skip to content

Commit

Permalink
Fixed using statement generation for nullable types #4454
Browse files Browse the repository at this point in the history
  • Loading branch information
jensbrand committed Jan 23, 2025
1 parent 6d4798a commit a529a48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ public string GetTypeNamespace(TypeDeclarationSyntax typeDeclarationSyntax)
public string GetTypeNamespace(TypeSyntax typeSyntax)
{
INamedTypeSymbol typeSymbol;
if (typeSyntax is NullableTypeSyntax nullableTypeSyntax)
{
typeSyntax = nullableTypeSyntax.ElementType;
}

if (typeSyntax is ArrayTypeSyntax arrayTypeSyntax)
{
typeSymbol = _semanticModel.GetSymbolInfo(arrayTypeSyntax.ElementType).Symbol as INamedTypeSymbol;
}
else
{

typeSymbol = _semanticModel.GetSymbolInfo(typeSyntax).Symbol as INamedTypeSymbol;
}
if (typeSymbol is null || typeSymbol.ContainingNamespace is null) return string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public string GetTypeNamespace(TypeDeclarationSyntax typeDeclarationSyntax)
public string GetTypeNamespace(TypeSyntax typeSyntax)
{
INamedTypeSymbol typeSymbol;

if (typeSyntax is NullableTypeSyntax nullableTypeSyntax)
{
typeSyntax = nullableTypeSyntax.ElementType;
}

typeSymbol = _semanticModel.GetSymbolInfo(typeSyntax).Symbol as INamedTypeSymbol;
if (typeSymbol is null || typeSymbol.ContainingNamespace is null) return string.Empty;
Expand Down

0 comments on commit a529a48

Please sign in to comment.