Update the FluentModelValidator in Samples

This commit is contained in:
Antony Male 2018-11-23 12:50:51 +00:00
parent aae13a8193
commit bc9578e8ea
1 changed files with 5 additions and 3 deletions

View File

@ -22,10 +22,12 @@ namespace Stylet.Samples.ModelValidation
this.subject = (T)subject;
}
public Task<IEnumerable<string>> ValidatePropertyAsync(string propertyName)
public async Task<IEnumerable<string>> ValidatePropertyAsync(string propertyName)
{
var errors = this.validator.Validate(this.subject, propertyName).Errors.Select(x => x.ErrorMessage);
return Task.FromResult(errors);
// If someone's calling us synchronously, and ValidationAsync does not complete synchronously,
// we'll deadlock unless we continue on another thread.
return (await this.validator.ValidateAsync(this.subject, CancellationToken.None, propertyName).ConfigureAwait(false))
.Errors.Select(x => x.ErrorMessage);
}
public async Task<Dictionary<string, IEnumerable<string>>> ValidateAllPropertiesAsync()