@@ -57,11 +57,11 @@ private static void Execute(SourceProductionContext context, EntityClass entityC
5757 private static bool SyntacticPredicate ( SyntaxNode syntaxNode , CancellationToken cancellationToken )
5858 {
5959 return syntaxNode is ClassDeclarationSyntax
60- { AttributeLists . Count : > 0 } classDeclaration
60+ { AttributeLists . Count : > 0 } classDeclaration
6161 && ! classDeclaration . Modifiers . Any ( SyntaxKind . AbstractKeyword )
6262 && ! classDeclaration . Modifiers . Any ( SyntaxKind . StaticKeyword )
6363 || syntaxNode is RecordDeclarationSyntax
64- { AttributeLists . Count : > 0 } recordDeclaration
64+ { AttributeLists . Count : > 0 } recordDeclaration
6565 && ! recordDeclaration . Modifiers . Any ( SyntaxKind . AbstractKeyword )
6666 && ! recordDeclaration . Modifiers . Any ( SyntaxKind . StaticKeyword ) ;
6767 }
@@ -78,12 +78,7 @@ private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext c
7878 ? InitializationMode . ObjectInitializer
7979 : InitializationMode . Constructor ;
8080
81- var propertySymbols = targetSymbol
82- . GetMembers ( )
83- . Where ( m => m . Kind == SymbolKind . Property )
84- . OfType < IPropertySymbol > ( )
85- . Where ( IsIncluded )
86- . ToList ( ) ;
81+ var propertySymbols = GetProperties ( targetSymbol ) ;
8782
8883 if ( mode == InitializationMode . ObjectInitializer )
8984 {
@@ -143,6 +138,31 @@ private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext c
143138 return new EntityContext ( entityClass , diagnostics ) ;
144139 }
145140
141+ private static List < IPropertySymbol > GetProperties ( INamedTypeSymbol targetSymbol )
142+ {
143+ var properties = new Dictionary < string , IPropertySymbol > ( ) ;
144+
145+ var currentSymbol = targetSymbol ;
146+
147+ // get nested properties
148+ while ( currentSymbol != null )
149+ {
150+ var propertySymbols = currentSymbol
151+ . GetMembers ( )
152+ . Where ( m => m . Kind == SymbolKind . Property )
153+ . OfType < IPropertySymbol > ( )
154+ . Where ( IsIncluded )
155+ . Where ( p => ! properties . ContainsKey ( p . Name ) ) ;
156+
157+ foreach ( var propertySymbol in propertySymbols )
158+ properties . Add ( propertySymbol . Name , propertySymbol ) ;
159+
160+ currentSymbol = currentSymbol . BaseType ;
161+ }
162+
163+ return properties . Values . ToList ( ) ;
164+ }
165+
146166 private static EntityProperty CreateProperty ( IPropertySymbol propertySymbol , string parameterName = null )
147167 {
148168 var propertyType = propertySymbol . Type . ToDisplayString ( ) ;
0 commit comments