Skip to content

Commit

Permalink
remove some redundant casts
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored and JeremySkinner committed Oct 5, 2024
1 parent 550ec5f commit f322bb3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/FluentValidation.Tests/InheritanceValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public async Task Validates_ruleset_async() {
[Fact]
public void Can_use_custom_subclass_with_nongeneric_overload() {
var validator = new InlineValidator<Root>();
validator.RuleFor(x => x.Foo).SetAsyncValidator((IAsyncPropertyValidator<Root, IFoo>) new TypeUnsafePolymorphicValidator<Root, IFoo>());
validator.RuleFor(x => x.Foo).SetAsyncValidator(new TypeUnsafePolymorphicValidator<Root, IFoo>());
var result = validator.Validate(new Root {Foo = new FooImpl1()});
result.Errors.Single().PropertyName.ShouldEqual("Foo.Name");
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentValidation.Tests/ValidateAndThrowTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void Populates_errors() {
v => v.RuleFor(x => x.Surname).NotNull()
};

var ex = (ValidationException) Assert.Throws<ValidationException>(() => validator.ValidateAndThrow(new Person()));
var ex = Assert.Throws<ValidationException>(() => validator.ValidateAndThrow(new Person()));
ex.Errors.Count().ShouldEqual(1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/FluentValidation/DefaultValidatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ public static IRuleBuilderOptions<T, TProperty> SetInheritanceValidator<T,TPrope
if (validatorConfiguration == null) throw new ArgumentNullException(nameof(validatorConfiguration));
var validator = new PolymorphicValidator<T, TProperty>();
validatorConfiguration(validator);
return ruleBuilder.SetAsyncValidator((IAsyncPropertyValidator<T, TProperty>) validator);
return ruleBuilder.SetAsyncValidator(validator);
}

private static string GetDisplayName<T, TProperty>(MemberInfo member, Expression<Func<T, TProperty>> expression)
Expand Down
8 changes: 4 additions & 4 deletions src/FluentValidation/DefaultValidatorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static IRuleBuilderOptionsConditions<T, TProperty> When<T,TProperty>(this
public static IRuleBuilderOptions<T, TProperty> When<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule, Func<T, ValidationContext<T>, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) {
predicate.Guard("A predicate must be specified when calling When.", nameof(predicate));
// Default behaviour for When/Unless as of v1.3 is to apply the condition to all previous validators in the chain.
Configurable(rule).ApplyCondition(ctx => predicate((T)ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx)), applyConditionTo);
Configurable(rule).ApplyCondition(ctx => predicate(ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx)), applyConditionTo);
return rule;
}

Expand All @@ -220,7 +220,7 @@ public static IRuleBuilderOptions<T, TProperty> When<T, TProperty>(this IRuleBui
public static IRuleBuilderOptionsConditions<T, TProperty> When<T, TProperty>(this IRuleBuilderOptionsConditions<T, TProperty> rule, Func<T, ValidationContext<T>, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) {
predicate.Guard("A predicate must be specified when calling When.", nameof(predicate));
// Default behaviour for When/Unless as of v1.3 is to apply the condition to all previous validators in the chain.
Configurable(rule).ApplyCondition(ctx => predicate((T)ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx)), applyConditionTo);
Configurable(rule).ApplyCondition(ctx => predicate(ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx)), applyConditionTo);
return rule;
}

Expand Down Expand Up @@ -313,7 +313,7 @@ public static IRuleBuilderOptionsConditions<T, TProperty> WhenAsync<T, TProperty
public static IRuleBuilderOptions<T, TProperty> WhenAsync<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule, Func<T, ValidationContext<T>, CancellationToken, Task<bool>> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) {
predicate.Guard("A predicate must be specified when calling WhenAsync.", nameof(predicate));
// Default behaviour for When/Unless as of v1.3 is to apply the condition to all previous validators in the chain.
Configurable(rule).ApplyAsyncCondition((ctx, ct) => predicate((T)ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx), ct), applyConditionTo);
Configurable(rule).ApplyAsyncCondition((ctx, ct) => predicate(ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx), ct), applyConditionTo);
return rule;
}

Expand All @@ -328,7 +328,7 @@ public static IRuleBuilderOptions<T, TProperty> WhenAsync<T, TProperty>(this IRu
public static IRuleBuilderOptionsConditions<T, TProperty> WhenAsync<T, TProperty>(this IRuleBuilderOptionsConditions<T, TProperty> rule, Func<T, ValidationContext<T>, CancellationToken, Task<bool>> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) {
predicate.Guard("A predicate must be specified when calling WhenAsync.", nameof(predicate));
// Default behaviour for When/Unless as of v1.3 is to apply the condition to all previous validators in the chain.
Configurable(rule).ApplyAsyncCondition((ctx, ct) => predicate((T)ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx), ct), applyConditionTo);
Configurable(rule).ApplyAsyncCondition((ctx, ct) => predicate(ctx.InstanceToValidate, ValidationContext<T>.GetFromNonGenericContext(ctx), ct), applyConditionTo);
return rule;
}

Expand Down

0 comments on commit f322bb3

Please sign in to comment.