Skip to content

Commit

Permalink
Minor fix to where IsAsync is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Jun 3, 2022
1 parent 87eb303 commit bdf440f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/FluentValidation/IValidationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public ValidationContext(T instanceToValidate, PropertyChain propertyChain, IVal
IsChildContext = context.IsChildContext,
RootContextData = context.RootContextData,
ThrowOnFailures = context.ThrowOnFailures,
_parentContext = context.ParentContext
_parentContext = context.ParentContext,
IsAsync = context.IsAsync
};
}

Expand All @@ -228,6 +229,7 @@ public ValidationContext(T instanceToValidate, PropertyChain propertyChain, IVal
RootContextData = context.RootContextData,
ThrowOnFailures = context.ThrowOnFailures,
_parentContext = context.ParentContext,
IsAsync = context.IsAsync
};
}

Expand Down
4 changes: 0 additions & 4 deletions src/FluentValidation/Internal/CollectionPropertyRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ public CollectionPropertyRule(MemberInfo member, Func<T, IEnumerable<TElement>>
}

async Task IValidationRuleInternal<T>.ValidateAsync(ValidationContext<T> context, CancellationToken cancellation) {
if (!context.IsAsync) {
context.IsAsync = true;
}

string displayName = GetDisplayName(context);

if (PropertyName == null && displayName == null) {
Expand Down
5 changes: 1 addition & 4 deletions src/FluentValidation/Internal/PropertyRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TProperty PropertyFunc(T instance)
/// <param name="context">Validation Context</param>
/// <returns>A collection of validation failures</returns>
public virtual void Validate(ValidationContext<T> context) {
// TODO: 12.x This method shouldn't be public
string displayName = GetDisplayName(context);

if (PropertyName == null && displayName == null) {
Expand Down Expand Up @@ -145,10 +146,6 @@ TProperty PropertyFunc(T instance)
/// <param name="cancellation"></param>
/// <returns>A collection of validation failures</returns>
public virtual async Task ValidateAsync(ValidationContext<T> context, CancellationToken cancellation) {
if (!context.IsAsync) {
context.IsAsync = true;
}

string displayName = GetDisplayName(context);

if (PropertyName == null && displayName == null) {
Expand Down
2 changes: 0 additions & 2 deletions src/FluentValidation/Validators/ChildValidatorAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ChildValidatorAdaptor<T,TProperty> : NoopPropertyValidator<T,TPrope
}

var newContext = CreateNewValidationContextForChildValidator(context, value);
var totalFailures = context.Failures.Count;

// If we're inside a collection with RuleForEach, then preserve the CollectionIndex placeholder
// and pass it down to child validator by caching it in the RootContextData which flows through to
Expand All @@ -75,7 +74,6 @@ public class ChildValidatorAdaptor<T,TProperty> : NoopPropertyValidator<T,TPrope
}

var newContext = CreateNewValidationContextForChildValidator(context, value);
var totalFailures = context.Failures.Count;

// If we're inside a collection with RuleForEach, then preserve the CollectionIndex placeholder
// and pass it down to child validator by caching it in the RootContextData which flows through to
Expand Down

0 comments on commit bdf440f

Please sign in to comment.