Created
June 1, 2020 21:33
-
-
Save Char0394/8f08e0498a0f0012b35297ff736d09d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidatablePair<T> : IValidatable<ValidatablePair<T>> | |
{ | |
public List<IValidationRule<ValidatablePair<T>>> Validations { get; } = new List<IValidationRule<ValidatablePair<T>>>(); | |
public bool IsValid { get; set; } = true; | |
public List<string> Errors { get; set; } = new List<string>(); | |
public ValidatableObject<T> Item1 { get; set; } = new ValidatableObject<T>(); | |
public ValidatableObject<T> Item2 { get; set; } = new ValidatableObject<T>(); | |
public event PropertyChangedEventHandler PropertyChanged; | |
public bool Validate() | |
{ | |
var item1IsValid = Item1.Validate(); | |
var item2IsValid = Item2.Validate(); | |
if (item1IsValid && item2IsValid) | |
{ | |
Errors.Clear(); | |
IEnumerable<string> errors = Validations.Where(v => !v.Check(this)) | |
.Select(v => v.ValidationMessage); | |
Errors = errors.ToList(); | |
Item2.Errors = Errors; | |
Item2.IsValid = !Errors.Any(); | |
} | |
IsValid = !Item1.Errors.Any() && !Item2.Errors.Any(); | |
return this.IsValid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment