refactor(api): derive field name from property being validated
This commit is contained in:
1 parent
f2667fd330
commit
6f62d4ce11
1 file changed
+4
-2
@@ -9,12 +9,14 @@ public record Request : IValidatableObject
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Username))
|
||||
{
|
||||
yield return new("The Username field is required.", [nameof(Username)]);
|
||||
var fieldName = nameof(Username);
|
||||
yield return new($"The {fieldName} field is required.", [fieldName]);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Password))
|
||||
{
|
||||
yield return new("The Password field is required.", [nameof(Password)]);
|
||||
var fieldName = nameof(Password);
|
||||
yield return new($"The {fieldName} field is required.", [fieldName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user