@@ -78,6 +78,7 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
7878 bool addRange = true ;
7979 bool addRequired = false ;
8080 bool addDisplay = false ;
81+ bool addDescription = false ;
8182 var typesBuilder = ImmutableArray . CreateBuilder < ITypeSymbol > ( ) ;
8283
8384 foreach ( AttributeData attributeData in symbol . GetAttributes ( ) )
@@ -110,6 +111,12 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
110111 {
111112 addDisplay = display ;
112113 }
114+
115+ if ( namedArgument . Key == nameof ( DataAnnotationValuesOptionsAttribute . Description )
116+ && namedArgument . Value . Value is bool description )
117+ {
118+ addDescription = description ;
119+ }
113120 }
114121 }
115122 else if ( attributeData . AttributeClass ? . Name == "DataAnnotationValuesToGenerateAttribute" &&
@@ -134,11 +141,12 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
134141 name ,
135142 nameSpace ,
136143 filePath ,
137- ExtractTypeInformation ( typesBuilder . ToImmutable ( ) , addStringLength , addRange , addRequired , addDisplay ) ,
144+ ExtractTypeInformation ( typesBuilder . ToImmutable ( ) , addStringLength , addRange , addRequired , addDisplay , addDescription ) ,
138145 addStringLength ,
139146 addRange ,
140147 addRequired ,
141- addDisplay
148+ addDisplay ,
149+ addDescription
142150 ) ;
143151 }
144152
@@ -167,6 +175,7 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
167175 bool addRange = true ;
168176 bool addRequired = false ;
169177 bool addDisplay = false ;
178+ bool addDescription = false ;
170179
171180 // Get configuration from the DataAnnotationValuesAttribute
172181 foreach ( AttributeData attributeData in symbol . GetAttributes ( ) )
@@ -199,6 +208,12 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
199208 {
200209 addDisplay = display ;
201210 }
211+
212+ if ( namedArgument . Key == nameof ( DataAnnotationValuesAttribute . Description )
213+ && namedArgument . Value . Value is bool description )
214+ {
215+ addDescription = description ;
216+ }
202217 }
203218 }
204219 }
@@ -211,11 +226,12 @@ static void Execute(in DataAnnotationValuesDetailedOptions toGenerate, SourcePro
211226 name ,
212227 nameSpace ,
213228 filePath ,
214- ExtractTypeInformation ( types , addStringLength , addRange , addRequired , addDisplay ) ,
229+ ExtractTypeInformation ( types , addStringLength , addRange , addRequired , addDisplay , addDescription ) ,
215230 addStringLength ,
216231 addRange ,
217232 addRequired ,
218- addDisplay
233+ addDisplay ,
234+ addDescription
219235 ) ;
220236 }
221237
@@ -224,7 +240,8 @@ static ImmutableArray<TypeInformation> ExtractTypeInformation(
224240 bool includeStringLength ,
225241 bool includeRange ,
226242 bool includeRequired ,
227- bool includeDisplay )
243+ bool includeDisplay ,
244+ bool includeDescription )
228245 {
229246 var builder = ImmutableArray . CreateBuilder < TypeInformation > ( ) ;
230247
@@ -239,6 +256,7 @@ static ImmutableArray<TypeInformation> ExtractTypeInformation(
239256 RangeInfo ? range = null ;
240257 bool isRequired = false ;
241258 DisplayInfo ? display = null ;
259+ DescriptionInfo ? description = null ;
242260
243261 // Check for StringLength attribute
244262 if ( includeStringLength )
@@ -318,7 +336,7 @@ static ImmutableArray<TypeInformation> ExtractTypeInformation(
318336 {
319337 string ? name = null ;
320338 string ? shortName = null ;
321- string ? description = null ;
339+ string ? displayDescription = null ;
322340
323341 // Extract named arguments
324342 foreach ( var namedArg in displayAttr . NamedArguments )
@@ -333,27 +351,46 @@ static ImmutableArray<TypeInformation> ExtractTypeInformation(
333351 }
334352 else if ( namedArg . Key == "Description" && namedArg . Value . Value is string descriptionValue )
335353 {
336- description = descriptionValue ;
354+ displayDescription = descriptionValue ;
337355 }
338356 }
339357
340358 // Only create DisplayInfo if at least one value is present
341- if ( name != null || shortName != null || description != null )
359+ if ( name != null || shortName != null || displayDescription != null )
360+ {
361+ display = new DisplayInfo ( name , shortName , displayDescription ) ;
362+ }
363+ }
364+ }
365+
366+ // Check for Description attribute
367+ if ( includeDescription )
368+ {
369+ var descriptionAttr = property . GetAttributes ( )
370+ . FirstOrDefault ( a => a . AttributeClass ? . Name == "DescriptionAttribute" &&
371+ a . AttributeClass ? . ContainingNamespace ? . ToDisplayString ( ) == "System.ComponentModel" ) ;
372+
373+ if ( descriptionAttr != null && descriptionAttr . ConstructorArguments . Length > 0 )
374+ {
375+ string ? text = descriptionAttr . ConstructorArguments [ 0 ] . Value as string ;
376+
377+ if ( text != null )
342378 {
343- display = new DisplayInfo ( name , shortName , description ) ;
379+ description = new DescriptionInfo ( text ) ;
344380 }
345381 }
346382 }
347383
348384 // Only add property if it has any attributes we're tracking
349- if ( stringLength . HasValue || range . HasValue || includeRequired || display . HasValue )
385+ if ( stringLength . HasValue || range . HasValue || includeRequired || display . HasValue || description . HasValue )
350386 {
351387 propertyInfos . Add ( new PropertyInformation (
352388 property . Name ,
353389 stringLength ,
354390 range ,
355391 isRequired ,
356- display ) ) ;
392+ display ,
393+ description ) ) ;
357394 }
358395 }
359396
0 commit comments