Skip to content

Commit a529a48

Browse files
committed
Fixed using statement generation for nullable types #4454
1 parent 6d4798a commit a529a48

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Source/Csla.Generators/cs/AutoImplementProperties/Csla.Generator.AutoImplementProperties.CSharp/AutoImplement/Discovery/DefinitionExtractionContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ public string GetTypeNamespace(TypeDeclarationSyntax typeDeclarationSyntax)
4848
public string GetTypeNamespace(TypeSyntax typeSyntax)
4949
{
5050
INamedTypeSymbol typeSymbol;
51+
if (typeSyntax is NullableTypeSyntax nullableTypeSyntax)
52+
{
53+
typeSyntax = nullableTypeSyntax.ElementType;
54+
}
55+
5156
if (typeSyntax is ArrayTypeSyntax arrayTypeSyntax)
5257
{
5358
typeSymbol = _semanticModel.GetSymbolInfo(arrayTypeSyntax.ElementType).Symbol as INamedTypeSymbol;
5459
}
5560
else
5661
{
62+
5763
typeSymbol = _semanticModel.GetSymbolInfo(typeSyntax).Symbol as INamedTypeSymbol;
5864
}
5965
if (typeSymbol is null || typeSymbol.ContainingNamespace is null) return string.Empty;

Source/Csla.Generators/cs/AutoSerialization/Csla.Generator.AutoSerialization.CSharp/AutoSerializable/Discovery/DefinitionExtractionContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public string GetTypeNamespace(TypeDeclarationSyntax typeDeclarationSyntax)
5454
public string GetTypeNamespace(TypeSyntax typeSyntax)
5555
{
5656
INamedTypeSymbol typeSymbol;
57+
58+
if (typeSyntax is NullableTypeSyntax nullableTypeSyntax)
59+
{
60+
typeSyntax = nullableTypeSyntax.ElementType;
61+
}
5762

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

0 commit comments

Comments
 (0)