1
+ using System ;
1
2
using System . Collections . Immutable ;
3
+ using System . Reflection ;
2
4
3
5
using FluentCommand . Generators . Internal ;
4
6
using FluentCommand . Generators . Models ;
@@ -143,10 +145,13 @@ private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext c
143
145
144
146
private static EntityProperty CreateProperty ( IPropertySymbol propertySymbol , string parameterName = null )
145
147
{
148
+ var propertyType = propertySymbol . Type . ToDisplayString ( ) ;
149
+ var propertyName = propertySymbol . Name ;
150
+
146
151
// look for custom field converter
147
152
var attributes = propertySymbol . GetAttributes ( ) ;
148
153
if ( attributes == null || attributes . Length == 0 )
149
- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
154
+ return new EntityProperty ( propertyName , propertyType , parameterName ) ;
150
155
151
156
var converter = attributes
152
157
. FirstOrDefault ( a => a . AttributeClass is
@@ -156,17 +161,39 @@ private static EntityProperty CreateProperty(IPropertySymbol propertySymbol, str
156
161
} ) ;
157
162
158
163
if ( converter == null )
159
- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
164
+ return new EntityProperty ( propertyName , propertyType , parameterName ) ;
160
165
161
- var converterType = converter . ConstructorArguments . Single ( ) ;
166
+ // attribute contructor
167
+ var converterType = converter . ConstructorArguments . FirstOrDefault ( ) ;
162
168
if ( converterType . Value is INamedTypeSymbol converterSymbol )
169
+ {
163
170
return new EntityProperty (
164
- propertySymbol . Name ,
165
- propertySymbol . Type . ToDisplayString ( ) ,
171
+ propertyName ,
172
+ propertyType ,
166
173
parameterName ,
167
174
converterSymbol . ToDisplayString ( ) ) ;
175
+ }
176
+
177
+ // generic attribute
178
+ var attributeClass = converter . AttributeClass ;
179
+ if ( attributeClass is { IsGenericType : true }
180
+ && attributeClass . TypeArguments . Length == attributeClass . TypeParameters . Length
181
+ && attributeClass . TypeArguments . Length == 1 )
182
+ {
183
+ var typeArgument = attributeClass . TypeArguments [ 0 ] ;
184
+ var converterString = typeArgument . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
185
+
186
+ return new EntityProperty (
187
+ propertyName ,
188
+ propertyType ,
189
+ parameterName ,
190
+ converterString ) ;
191
+ }
168
192
169
- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
193
+ return new EntityProperty (
194
+ propertyName ,
195
+ propertyType ,
196
+ parameterName ) ;
170
197
}
171
198
172
199
private static bool IsIncluded ( IPropertySymbol propertySymbol )
0 commit comments