Skip to content

Commit 7ec2163

Browse files
committed
Adds support for class attributes. Turns on MaxLength and MinLength by default. Disables warning CS0108 in generated code. Make string constants have type string if not null, otherwise string?.
1 parent 45e2488 commit 7ec2163

File tree

68 files changed

+642
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+642
-434
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ the following properties to control which constants are generated:
179179
| Property | Default | Generated Constants | Description |
180180
| -------------- | ------- | ---------------------------------------------------------------- | ----------------------------------------------- |
181181
| `StringLength` | `true` | `MaximumLength`, `MinimumLength` | Extract values from `[StringLength]` attribute. |
182-
| `MinLength` | `false` | `MinLength` | Extract value from `[MinLength]` attribute. |
183-
| `MaxLength` | `false` | `MaxLength` | Extract value from `[MaxLength]` attribute. |
182+
| `MinLength` | `true` | `MinLength` | Extract value from `[MinLength]` attribute. |
183+
| `MaxLength` | `true` | `MaxLength` | Extract value from `[MaxLength]` attribute. |
184184
| `Range` | `true` | `Minimum`, `Maximum`, `MinimumIsExclusive`, `MaximumIsExclusive` | Extract values from `[Range]` attribute. |
185185
| `Required` | `false` | `IsRequired` | Detect presence of `[Required]` attribute. |
186186
| `Display` | `false` | `Name`, `Description`, `ShortName` | Extract values from `[Display]` attribute. |

Source/Library/Pekspro.DataAnnotationValuesExtractor.Attributes/DataAnnotationValuesAttribute.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ public class DataAnnotationValuesAttribute : System.Attribute
1313
/// </summary>
1414
public bool StringLength { get; set; } = true;
1515

16+
/// <summary>
17+
/// Whether MaxLength attribute values should be included.
18+
/// Is set to true by default.
19+
/// </summary>
20+
public bool MaxLength { get; set; } = true;
21+
22+
/// <summary>
23+
/// Whether MinLength attribute values should be included.
24+
/// Is set to true by default.
25+
/// </summary>
26+
public bool MinLength { get; set; } = true;
27+
1628
/// <summary>
1729
/// Whether Range attribute values should be included.
1830
/// Is set to true by default.
@@ -36,18 +48,6 @@ public class DataAnnotationValuesAttribute : System.Attribute
3648
/// Is set to false by default.
3749
/// </summary>
3850
public bool Description { get; set; }
39-
40-
/// <summary>
41-
/// Whether MaxLength attribute values should be included.
42-
/// Is set to false by default.
43-
/// </summary>
44-
public bool MaxLength { get; set; }
45-
46-
/// <summary>
47-
/// Whether MinLength attribute values should be included.
48-
/// Is set to false by default.
49-
/// </summary>
50-
public bool MinLength { get; set; }
5151
}
5252
}
5353

Source/Library/Pekspro.DataAnnotationValuesExtractor.Attributes/DataAnnotationValuesOptionsAttribute.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ public class DataAnnotationValuesOptionsAttribute : System.Attribute
1515
/// </summary>
1616
public bool StringLength { get; set; } = true;
1717

18+
/// <summary>
19+
/// Whether MaxLength attribute values should be included.
20+
/// Is set to true by default.
21+
/// </summary>
22+
public bool MaxLength { get; set; } = true;
23+
24+
/// <summary>
25+
/// Whether MinLength attribute values should be included.
26+
/// Is set to true by default.
27+
/// </summary>
28+
public bool MinLength { get; set; } = true;
29+
1830
/// <summary>
1931
/// Whether Range attribute values should be included.
2032
/// Is set to true by default.
@@ -38,18 +50,6 @@ public class DataAnnotationValuesOptionsAttribute : System.Attribute
3850
/// Is set to false by default.
3951
/// </summary>
4052
public bool Description { get; set; }
41-
42-
/// <summary>
43-
/// Whether MaxLength attribute values should be included.
44-
/// Is set to false by default.
45-
/// </summary>
46-
public bool MaxLength { get; set; }
47-
48-
/// <summary>
49-
/// Whether MinLength attribute values should be included.
50-
/// Is set to false by default.
51-
/// </summary>
52-
public bool MinLength { get; set; }
5353
}
5454
}
5555

Source/Library/Pekspro.DataAnnotationValuesExtractor/DataAnnotationValuesDetailedOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public DataAnnotationValuesDetailedOptions(
2929
bool addRequired,
3030
bool addDisplay = false,
3131
bool addDescription = false,
32-
bool addMaxLength = false,
33-
bool addMinLength = false
32+
bool addMaxLength = true,
33+
bool addMinLength = true
3434
)
3535
{
3636
Name = name;

0 commit comments

Comments
 (0)