private void ValidateProperty(IPropertyMetadata property) { var context = new ValidationContext(Entity, _serviceProvider, null) { MemberName = property.PropertyName }; var results = new List <ValidationResult>(); try { // even though this says Try, and therefore it should not throw an error, IT DOES when a given property is not part of Entity Validator.TryValidateProperty(property.Getter(Entity), context, results); } catch { } foreach (var result in DataProviders.Where(p => p.Property == property).SelectMany(p => p.Validate(Entity, _serviceProvider))) { results.Add(result); } var state = GetPropertyState(property); state.ClearMessages(); state.WasValidated = true; foreach (var result in results) { state.AddMessage(result.ErrorMessage); } OnValidationStateChanged?.Invoke(this, new ValidationStateChangedEventArgs(isValid: !HasValidationMessages())); }
private void ValidateModel() { var context = new ValidationContext(Entity, _serviceProvider, null); var results = new List <ValidationResult>(); try { // even though this says Try, and therefore it should not throw an error, IT DOES when a given property is not part of Entity Validator.TryValidateObject(Entity, context, results, true); } catch { } ClearAllFieldStates(); _fieldStates .Where(kv => kv.Value.IsBusy) .ForEach(kv => results.Add(new ValidationResult( $"The {kv.Key.PropertyName} field indicates it is performing an asynchronous task which must be awaited.", new[] { kv.Key.PropertyName }))); foreach (var result in DataProviders.SelectMany(p => p.Validate(Entity, _serviceProvider))) { results.Add(result); } foreach (var result in results) { if (!result.MemberNames.Any()) { throw new InvalidOperationException("Only validators which explicitly specify which member is invalid should be used."); } result.MemberNames.ForEach(name => GetFieldState(name)?.AddMessage(result.ErrorMessage)); } _fieldStates.ForEach(kv => kv.Value.WasValidated = true); OnValidationStateChanged?.Invoke(this, new ValidationStateChangedEventArgs(isValid: !HasValidationMessages())); }
public void NotifyPropertyFinished(IPropertyMetadata property) { GetPropertyState(property) !.IsBusy = false; OnValidationStateChanged?.Invoke(this, new ValidationStateChangedEventArgs()); }
public void NotifyPropertyBusy(IPropertyMetadata property) { GetPropertyState(property).IsBusy = true; OnValidationStateChanged?.Invoke(this, new ValidationStateChangedEventArgs(false)); }
private void OnValidationStateChangedHandler(object sender, ValidationStateChangedEventArgs e) => InvokeAsync(() => OnValidationStateChanged.InvokeAsync(e));