`EmailAttribute` should allow null values
alexrp opened this issue · comments
Specifically:
EmailValidation/EmailValidation/EmailAttribute.cs
Lines 86 to 87 in 643a8e3
Most (all?) attributes in System.ComponentModel.DataAnnotations
of a similar nature to EmailAttribute
consider null to be valid.
Examples:
- https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/PhoneAttribute.cs#L23-L28
- https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/CreditCardAttribute.cs#L18-L23
- https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/RegularExpressionAttribute.cs#L63-L67
Generally speaking, one should use RequiredAttribute
if a value should not be allowed to be null. (Higher-level frameworks like ASP.NET Core will additionally use C# nullability annotations to infer RequiredAttribute
.)
(Aside: The allocation of memberNames
is pointless in the success case.)
Seems reasonable. Hopefully won't break any existing apps due to a change in expectations.