Skip to content

Commit d4b6abe

Browse files
authored
Merge pull request #5 from Codelisk/feature/audit-modell
more updates
2 parents 98e4a43 + b1d5b67 commit d4b6abe

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

src/GeneratorHelper/Generators.Base/Extensions/New/RecordDeclarationSyntaxExtensions.cs

+30-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,36 @@ public static IEnumerable<PropertyDeclarationSyntax> GetProperties(
115115
this RecordDeclarationSyntax classSyntax
116116
)
117117
{
118-
return classSyntax.Members.OfType<PropertyDeclarationSyntax>();
118+
// Get explicit properties from the record's members
119+
var explicitProperties = classSyntax.Members.OfType<PropertyDeclarationSyntax>();
120+
121+
// Get positional parameters from the primary constructor and create PropertyDeclarationSyntax for them
122+
var positionalParameters =
123+
classSyntax.ParameterList?.Parameters.Select(param =>
124+
SyntaxFactory
125+
.PropertyDeclaration(
126+
param.Type,
127+
SyntaxFactory.Identifier(param.Identifier.Text)
128+
)
129+
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
130+
.WithAccessorList(
131+
SyntaxFactory.AccessorList(
132+
SyntaxFactory.List(
133+
new[]
134+
{
135+
SyntaxFactory
136+
.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
137+
.WithSemicolonToken(
138+
SyntaxFactory.Token(SyntaxKind.SemicolonToken)
139+
)
140+
}
141+
)
142+
)
143+
)
144+
) ?? Enumerable.Empty<PropertyDeclarationSyntax>();
145+
146+
// Combine explicit properties and positional parameters
147+
return explicitProperties.Concat(positionalParameters);
119148
}
120149

121150
// Hilfsmethode, um eine Klasse im Syntaxbaum zu finden

src/Generators/Foundation/Codelisk.Foundation.Generator/Generators/EntityGenerator.cs

+8-14
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,14 @@ IEnumerable<RecordDeclarationSyntax> baseDtos
6666
.AddAttribute($"{typeof(EntityAttribute).FullName}(typeof({dto.Identifier.Text}))")
6767
.WithAccessModifier(Accessibility.Public);
6868

69-
result.AddConstructor();
70-
var constructor = result.AddConstructor().AddParameter(dto.Identifier.Text);
71-
72-
var allProperties = dto.DtoProperties(baseDtos);
73-
74-
constructor.WithBody(x =>
75-
{
76-
foreach (var property in allProperties)
77-
{
78-
x.AppendLine(
79-
$"this.{property.GetPropertyName()} = {dto.GetName().GetParameterName()}.{property.GetPropertyName()};"
80-
);
81-
}
82-
});
69+
var constructor = result
70+
.AddConstructor()
71+
.WithBaseCall(
72+
new Dictionary<string, string>
73+
{
74+
{ dto.GetFullTypeName(), dto.Identifier.Text }
75+
}
76+
);
8377

8478
return builder.Classes;
8579
}

0 commit comments

Comments
 (0)