Skip to content

Commit 353cd67

Browse files
committed
Add missing ErrorCodeSource on all Validator Constructors
1 parent 78c64b4 commit 353cd67

12 files changed

Lines changed: 200 additions & 6 deletions

src/ServiceStack/FluentValidation/ValidationErrors.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public static class ValidationErrors
99
{
1010
public const string CreditCard = "CreditCard";
1111
public const string Email = "Email";
12+
public const string Enum = "Enum";
13+
public const string Empty = "Empty";
1214
public const string Equal = "Equal";
1315
public const string ExclusiveBetween = "ExclusiveBetween";
1416
public const string GreaterThanOrEqual = "GreaterThanOrEqual";
@@ -20,7 +22,9 @@ public static class ValidationErrors
2022
public const string NotEmpty = "NotEmpty";
2123
public const string NotEqual = "NotEqual";
2224
public const string NotNull = "NotNull";
25+
public const string Null = "Null";
2326
public const string Predicate = "Predicate";
2427
public const string RegularExpression = "RegularExpression";
28+
public const string ScalePrecision = "ScalePrecision";
2529
}
2630
}

src/ServiceStack/FluentValidation/Validators/EmptyValidator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class EmptyValidator : PropertyValidator, IEmptyValidator {
2525
readonly object defaultValueForType;
2626

2727
public EmptyValidator(object defaultValueForType) : base(nameof(Messages.empty_error), typeof(Messages)) {
28+
ErrorCodeSource = new StaticStringSource(ValidationErrors.Empty);
2829
this.defaultValueForType = defaultValueForType;
2930
}
3031

src/ServiceStack/FluentValidation/Validators/EnumValidator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class EnumValidator : PropertyValidator
2727
private readonly Type enumType;
2828

2929
public EnumValidator(Type enumType) : base(nameof(Messages.enum_error), typeof(Messages)) {
30+
ErrorCodeSource = new StaticStringSource(ValidationErrors.Enum);
3031
this.enumType = enumType;
3132
}
3233

src/ServiceStack/FluentValidation/Validators/GreaterThanOrEqualValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public GreaterThanOrEqualValidator(IComparable value) : base(value, nameof(Messa
3030

3131
public GreaterThanOrEqualValidator(Func<object, object> valueToCompareFunc, MemberInfo member)
3232
: base(valueToCompareFunc, member, nameof(Messages.greaterthanorequal_error), typeof(Messages)) {
33+
ErrorCodeSource = new StaticStringSource(ValidationErrors.GreaterThanOrEqual);
3334
}
3435

35-
public override bool IsValid(IComparable value, IComparable valueToCompare) {
36+
public override bool IsValid(IComparable value, IComparable valueToCompare) {
3637
if (valueToCompare == null)
3738
return false;
3839

src/ServiceStack/FluentValidation/Validators/GreaterThanValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public GreaterThanValidator(IComparable value) : base(value, nameof(Messages.gre
3131

3232
public GreaterThanValidator(Func<object, object> valueToCompareFunc, MemberInfo member)
3333
: base(valueToCompareFunc, member, nameof(Messages.greaterthan_error), typeof(Messages)) {
34+
ErrorCodeSource = new StaticStringSource(ValidationErrors.GreaterThan);
3435
}
3536

36-
public override bool IsValid(IComparable value, IComparable valueToCompare) {
37+
public override bool IsValid(IComparable value, IComparable valueToCompare) {
3738
if (valueToCompare == null)
3839
return false;
3940

src/ServiceStack/FluentValidation/Validators/LengthValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class LengthValidator : PropertyValidator, ILengthValidator {
3030
public Func<object, int> MaxFunc { get; set; }
3131

3232
public LengthValidator(int min, int max) : this(min, max, nameof(Messages.length_error), typeof(Messages)) {
33-
ErrorCodeSource = new StaticStringSource(ValidationErrors.Length);
3433
}
3534

3635
public LengthValidator(int min, int max, string resourceName, Type resourceType) : base(resourceName, resourceType) {
36+
ErrorCodeSource = new StaticStringSource(ValidationErrors.Length);
3737
Max = max;
3838
Min = min;
3939

@@ -47,6 +47,7 @@ public LengthValidator(Func<object, int> min, Func<object, int> max)
4747
}
4848

4949
public LengthValidator(Func<object, int> min, Func<object, int> max, string resourceName, Type resourceType) : base(resourceName, resourceType) {
50+
ErrorCodeSource = new StaticStringSource(ValidationErrors.Length);
5051
MaxFunc = max;
5152
MinFunc = min;
5253
}

src/ServiceStack/FluentValidation/Validators/LessThanOrEqualValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public LessThanOrEqualValidator(IComparable value)
3636
public LessThanOrEqualValidator(Func<object, object> valueToCompareFunc, MemberInfo member)
3737
: base(valueToCompareFunc, member, nameof(Messages.lessthanorequal_error), typeof(Messages))
3838
{
39+
ErrorCodeSource = new StaticStringSource(ValidationErrors.LessThanOrEqual);
3940
}
4041

41-
public override bool IsValid(IComparable value, IComparable valueToCompare)
42+
public override bool IsValid(IComparable value, IComparable valueToCompare)
4243
{
4344
if (valueToCompare == null)
4445
return false;

src/ServiceStack/FluentValidation/Validators/LessThanValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public LessThanValidator(IComparable value) : base(value, nameof(Messages.lessth
3232

3333
public LessThanValidator(Func<object, object> valueToCompareFunc, MemberInfo member)
3434
: base(valueToCompareFunc, member, nameof(Messages.lessthan_error), typeof(Messages)) {
35+
ErrorCodeSource = new StaticStringSource(ValidationErrors.LessThan);
3536
}
3637

37-
public override bool IsValid(IComparable value, IComparable valueToCompare) {
38+
public override bool IsValid(IComparable value, IComparable valueToCompare) {
3839
if (valueToCompare == null)
3940
return false;
4041

src/ServiceStack/FluentValidation/Validators/NullValidator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ namespace ServiceStack.FluentValidation.Validators
2222

2323
public class NullValidator : PropertyValidator, INullValidator {
2424
public NullValidator() : base(nameof(Messages.null_error), typeof(Messages)) {
25+
ErrorCodeSource = new StaticStringSource(ValidationErrors.Null);
2526
}
2627

27-
protected override bool IsValid(PropertyValidatorContext context) {
28+
protected override bool IsValid(PropertyValidatorContext context) {
2829
if (context.PropertyValue != null) {
2930
return false;
3031
}

src/ServiceStack/FluentValidation/Validators/RegularExpressionValidator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,34 @@ public RegularExpressionValidator(string expression) : base(nameof(Messages.rege
3838
}
3939

4040
public RegularExpressionValidator(Regex regex) : base(nameof(Messages.regex_error), typeof(Messages)) {
41+
ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression);
4142
this.expression = regex.ToString();
4243
this.regexFunc = x => regex;
4344
}
4445

4546
public RegularExpressionValidator(string expression, RegexOptions options) : base(nameof(Messages.regex_error), typeof(Messages)) {
47+
ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression);
4648
this.expression = expression;
4749
var regex = new Regex(expression, options);
4850
this.regexFunc = x => regex;
4951
}
5052

5153
public RegularExpressionValidator(Func<object, string> expressionFunc)
5254
: base(nameof(Messages.regex_error), typeof(Messages)) {
55+
ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression);
5356
this.regexFunc = x => new Regex(expressionFunc(x));
5457
}
5558

5659
public RegularExpressionValidator(Func<object, Regex> regexFunc)
5760
: base(nameof(Messages.regex_error), typeof(Messages)) {
61+
ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression);
5862
this.regexFunc = regexFunc;
5963
}
6064

6165
public RegularExpressionValidator(Func<object, string> expression, RegexOptions options)
6266
: base(nameof(Messages.regex_error), typeof(Messages)) {
6367

68+
ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression);
6469
this.regexFunc = x => new Regex(expression(x), options);
6570
}
6671

0 commit comments

Comments
 (0)