Skip to content

Commit 8b8a981

Browse files
committed
fix bug with reader generation
1 parent 64c8065 commit 8b8a981

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/FluentCommand.Generators/DataReaderFactoryGenerator.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace FluentCommand.Tests.Models;
4+
5+
[Table(nameof(Truck))]
6+
public class Truck : Vehicle
7+
{
8+
public string Color { get; set; }
9+
public override int Type { get; set; }
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace FluentCommand.Tests.Models;
4+
5+
[Table(nameof(Vehicle))]
6+
public class Vehicle
7+
{
8+
public string Name { get; set; }
9+
public virtual int Type { get; set; }
10+
}

0 commit comments

Comments
 (0)