File tree 2 files changed +38
-15
lines changed
GeneratorHelper/Generators.Base/Extensions/New
Generators/Foundation/Codelisk.Foundation.Generator/Generators
2 files changed +38
-15
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,36 @@ public static IEnumerable<PropertyDeclarationSyntax> GetProperties(
115
115
this RecordDeclarationSyntax classSyntax
116
116
)
117
117
{
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 ) ;
119
148
}
120
149
121
150
// Hilfsmethode, um eine Klasse im Syntaxbaum zu finden
Original file line number Diff line number Diff line change @@ -66,20 +66,14 @@ IEnumerable<RecordDeclarationSyntax> baseDtos
66
66
. AddAttribute ( $ "{ typeof ( EntityAttribute ) . FullName } (typeof({ dto . Identifier . Text } ))")
67
67
. WithAccessModifier ( Accessibility . Public ) ;
68
68
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
+ ) ;
83
77
84
78
return builder . Classes ;
85
79
}
You can’t perform that action at this time.
0 commit comments