@@ -6,8 +6,8 @@ status](https://github.com/pekspro/DataAnnotationValuesExtractor/actions/workflo
66
77A C# source generator that automatically extracts values from data annotation
88attributes and exposes them as strongly-typed constants. Access your
9- ` StringLength ` , ` Range ` , and ` Required ` attribute values at constants in your
10- classes.
9+ ` StringLength ` , ` Range ` , ` Required ` and ` Display ` attribute values as constants
10+ in your classes.
1111
1212## Why Use This?
1313
@@ -46,7 +46,7 @@ double maxPrice = Product.Annotations.Price.Maximum; // 999999.99
4646
4747## Usage Patterns
4848
49- There are two ways configure use DataAnnotationValuesExtractor depending on your
49+ There are two ways to configure DataAnnotationValuesExtractor depending on your
5050needs:
5151
5252### 1. Direct Approach
@@ -55,13 +55,15 @@ Apply `[DataAnnotationValues]` directly to each class you want to generate
5555constants for:
5656
5757``` csharp
58- [DataAnnotationValues (StringLength = true , Range = true , Required = true )]
58+ [DataAnnotationValues (StringLength = true , Range = true , Required = true , Display = true )]
5959public partial class Product
6060{
61+ [Display (Name = " Product name" )]
6162 [Required ]
6263 [StringLength (100 )]
6364 public string ? Name { get ; set ; }
6465
66+ [Display (Name = " Product price" )]
6567 [Required ]
6668 [Range (0 . 01 , 999999 . 99 )]
6769 public decimal Price { get ; set ; }
@@ -79,7 +81,7 @@ each class you want to generate constants for. You can use the
7981``` csharp
8082using Pekspro .DataAnnotationValuesExtractor ;
8183
82- [DataAnnotationValuesConfiguration (StringLength = true , Range = true , Required = true )]
84+ [DataAnnotationValuesConfiguration (StringLength = true , Range = true , Required = true , Display = true )]
8385[DataAnnotationValuesToGenerate (typeof (Customer ))]
8486[DataAnnotationValuesToGenerate (typeof (Order ))]
8587[DataAnnotationValuesToGenerate (typeof (Product ))]
@@ -108,17 +110,19 @@ No matter which approach your are using, you can access generated constants like
108110this:
109111
110112``` csharp
111- // Name length constraints
113+ // Name
112114int maxNameLength = Product .Annotations .Name .MaximumLength ; // 100
113115int minNameLength = Product .Annotations .Name .MinimumLength ; // 0
114116bool nameRequired = Product .Annotations .Name .IsRequired ; // true
117+ string ? nameDisplayName = Product .Annotations .Name .Display .Name ; // Product name
115118
116- // Price constraints
119+ // Price
117120double minPrice = Product .Annotations .Price .Minimum ; // 0.01
118121double maxPrice = Product .Annotations .Price .Maximum ; // 999999.99
119122bool priceRequired = Product .Annotations .Price .IsRequired ;
123+ string ? priceDisplayName = Product .Annotations .Price .Display .Name ; // Price name
120124
121- // Sky constraints
125+ // Sku
122126bool skuRequired = Product .Annotations .Sku .IsRequired ; // false
123127```
124128
@@ -157,6 +161,7 @@ the following properties to control which constants are generated:
157161| ` StringLength ` | ` true ` | ` MaximumLength ` , ` MinimumLength ` | Extract values from ` [StringLength] ` attribute. |
158162| ` Range ` | ` true ` | ` Minimum ` , ` Maximum ` , ` MinimumIsExclusive ` , ` MaximumIsExclusive ` | Extract values from ` [Range] ` attribute. |
159163| ` Required ` | ` false ` | ` IsRequired ` | Detect presence of ` [Required] ` attribute. |
164+ | ` Display ` | ` false ` | ` Name ` , ` Description ` , ` ShortName ` | Extract values from ` [Display] ` attribute. |
160165
161166Do you miss some annotations? Create an issue and let me know.
162167
@@ -188,9 +193,10 @@ directory.
188193Given this input:
189194
190195``` csharp
191- [DataAnnotationValues (StringLength = true , Range = true , Required = true )]
196+ [DataAnnotationValues (StringLength = true , Range = true , Required = true , Display = true )]
192197public partial class Player
193198{
199+ [Display (Name = " Player name" , ShortName = " Name" , Description = " Name of player" )]
194200 [Required ]
195201 [StringLength (50 )]
196202 public string ? Name { get ; set ; }
@@ -232,6 +238,27 @@ public partial class Player
232238 /// Indicates whether Name is required.
233239 /// </summary >
234240 public const bool IsRequired = true ;
241+
242+ /// <summary >
243+ /// Display attribute values for Name.
244+ /// </summary >
245+ public static class Display
246+ {
247+ /// <summary >
248+ /// Display name for Name.
249+ /// </summary >
250+ public const string ? Name = " Player name" ;
251+
252+ /// <summary >
253+ /// Short display name for Name.
254+ /// </summary >
255+ public const string ? ShortName = " Name" ;
256+
257+ /// <summary >
258+ /// Description for Name.
259+ /// </summary >
260+ public const string ? Description = " Name of player" ;
261+ }
235262 }
236263
237264 /// <summary >
0 commit comments