Skip to content

Commit 18b3077

Browse files
committed
Add missing attributes
1 parent d644bc8 commit 18b3077

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Moryx/Serialization/DefaultSerialization.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ public virtual string[] PossibleValues(Type memberType, ICustomAttributeProvider
7676
{
7777
#if NET8_0
7878
var validationAttribute = attributeProvider.GetCustomAttribute<AllowedValuesAttribute>();
79-
var allowedValues = validationAttribute?.Values.Select(o => o.ToString()) ?? Enumerable.Empty<string>();
80-
if (allowedValues.All(value => !string.IsNullOrEmpty(value)))
81-
return allowedValues?.Distinct().ToArray();
79+
if (validationAttribute != null)
80+
{
81+
var allowedValues = validationAttribute.Values.Select(o => o.ToString());
82+
return allowedValues?.Distinct().ToArray();
83+
}
8284
#endif
8385

8486
// Element type for collections
@@ -130,6 +132,15 @@ public virtual EntryValidation CreateValidation(Type memberType, ICustomAttribut
130132
validation.IsRequired = true;
131133
break;
132134

135+
case RegularExpressionAttribute regexAttribute:
136+
validation.Regex = regexAttribute.Pattern;
137+
break;
138+
139+
case StringLengthAttribute strLength:
140+
validation.Minimum = strLength.MinimumLength;
141+
validation.Maximum = strLength.MaximumLength;
142+
break;
143+
133144
#if NET8_0
134145
case DeniedValuesAttribute deniedAttribute:
135146
object[] denied = deniedAttribute.Values;

0 commit comments

Comments
 (0)