1+ using System ;
12using System . Collections . Immutable ;
3+ using System . Reflection ;
24
35using FluentCommand . Generators . Internal ;
46using FluentCommand . Generators . Models ;
@@ -143,10 +145,13 @@ private static EntityContext SemanticTransform(GeneratorAttributeSyntaxContext c
143145
144146 private static EntityProperty CreateProperty ( IPropertySymbol propertySymbol , string parameterName = null )
145147 {
148+ var propertyType = propertySymbol . Type . ToDisplayString ( ) ;
149+ var propertyName = propertySymbol . Name ;
150+
146151 // look for custom field converter
147152 var attributes = propertySymbol . GetAttributes ( ) ;
148153 if ( attributes == null || attributes . Length == 0 )
149- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
154+ return new EntityProperty ( propertyName , propertyType , parameterName ) ;
150155
151156 var converter = attributes
152157 . FirstOrDefault ( a => a . AttributeClass is
@@ -156,17 +161,39 @@ private static EntityProperty CreateProperty(IPropertySymbol propertySymbol, str
156161 } ) ;
157162
158163 if ( converter == null )
159- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
164+ return new EntityProperty ( propertyName , propertyType , parameterName ) ;
160165
161- var converterType = converter . ConstructorArguments . Single ( ) ;
166+ // attribute contructor
167+ var converterType = converter . ConstructorArguments . FirstOrDefault ( ) ;
162168 if ( converterType . Value is INamedTypeSymbol converterSymbol )
169+ {
163170 return new EntityProperty (
164- propertySymbol . Name ,
165- propertySymbol . Type . ToDisplayString ( ) ,
171+ propertyName ,
172+ propertyType ,
166173 parameterName ,
167174 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+ }
168192
169- return new EntityProperty ( propertySymbol . Name , propertySymbol . Type . ToDisplayString ( ) , parameterName ) ;
193+ return new EntityProperty (
194+ propertyName ,
195+ propertyType ,
196+ parameterName ) ;
170197 }
171198
172199 private static bool IsIncluded ( IPropertySymbol propertySymbol )
0 commit comments