Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
matthetherington-pa committed Dec 7, 2023
1 parent b0d9a97 commit a3304ae
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,7 @@ private static async Task ValidateModel(EditContext editContext,

if (validator is not null)
{
ValidationContext<object> context;

if (fluentValidationValidator.ValidateOptions is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.ValidateOptions);
}
else if (fluentValidationValidator.Options is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.Options);
}
else
{
context = new ValidationContext<object>(editContext.Model);
}
var context = ConstructValidationContext(editContext, fluentValidationValidator);

var asyncValidationTask = validator.ValidateAsync(context);
editContext.Properties[PendingAsyncValidation] = asyncValidationTask;
Expand Down Expand Up @@ -82,20 +69,7 @@ private static async Task ValidateField(EditContext editContext,
return;
}

ValidationContext<object> context;

if (fluentValidationValidator.ValidateOptions is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.ValidateOptions);
}
else if (fluentValidationValidator.Options is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.Options);
}
else
{
context = new ValidationContext<object>(editContext.Model);
}
var context = ConstructValidationContext(editContext, fluentValidationValidator);

var fluentValidationValidatorSelector = context.Selector;
var changedPropertySelector = ValidationContext<object>.CreateWithOptions(editContext.Model, strategy =>
Expand All @@ -122,6 +96,27 @@ private static async Task ValidateField(EditContext editContext,
}
}

private static ValidationContext<object> ConstructValidationContext(EditContext editContext,
FluentValidationValidator fluentValidationValidator)
{
ValidationContext<object> context;

if (fluentValidationValidator.ValidateOptions is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.ValidateOptions);
}
else if (fluentValidationValidator.Options is not null)
{
context = ValidationContext<object>.CreateWithOptions(editContext.Model, fluentValidationValidator.Options);
}
else
{
context = new ValidationContext<object>(editContext.Model);
}

return context;
}

private static IValidator? GetValidatorForModel(IServiceProvider serviceProvider, object model, bool disableAssemblyScanning)
{
var validatorType = typeof(IValidator<>).MakeGenericType(model.GetType());
Expand Down

0 comments on commit a3304ae

Please sign in to comment.