public static void backToDefault() { InvalidChars = new List<string>(); InvalidChars.Add("'"); InvalidChars.Add("*"); InvalidChars.Add("#"); InvalidChars.Add(";"); CustomMessage = ""; Source = ""; CaseSensitive = false; valList = null; }
public ValidatableObject(IValidity viewmodel) : this() { _viewmodel = new WeakReference <IValidity>(viewmodel); }
public static void newValidator(IValidity val) { valList = val; }
/// <summary> /// Takes a validation result and applies the rule results relevant to the <see cref="Validatable{T}"/>object. /// </summary> /// <param name="valResult">The original Fluent <see cref="ValidationResult"/> from a class instance that contains the value of the individual <see cref="Validatable{T}"/>object property.</param> /// <param name="validatableObj">The <see cref="Validatable{T}"/>object property to apply results to.</param> /// <returns>An <see cref="OverallValidationResult"/> summarizing the original results (on the entire instance) as well as any rule results that were not captured by the <see cref="Validatable{T}"/>object.</returns> public static OverallValidationResult ApplyResultsTo(this ValidationResult valResult, IValidity validatableObj) { var overallResult = new OverallValidationResult { IsValidOverall = valResult.IsValid, AllErrors = valResult.Errors.Select(e => e.ErrorMessage).ToList() }; overallResult.NonSplitErrors = overallResult.AllErrors; validatableObj.IsValid = true; var relevantFailures = valResult.Errors .Where(e => e.PropertyName == validatableObj.ClassPropertyName).ToList(); if (!relevantFailures.Any()) { return(overallResult); } var errors = relevantFailures.Select(e => e.ErrorMessage).ToList(); validatableObj.Errors = errors; validatableObj.IsValid = false; relevantFailures.ForEach(failure => valResult.Errors.Remove(failure)); overallResult.NonSplitErrors = valResult.Errors.Select(e => e.ErrorMessage).ToList(); overallResult.IsValidForNonSplitErrors = overallResult.NonSplitErrors.Count == 0; return(overallResult); }
/// <summary> /// Returns the ValidationRule objects from an <see cref="AbstractValidator{T}"/> that are relevant to the given <see cref="Validatable{T}"/>object. /// </summary> /// <typeparam name="T">The Type of the class that the <see cref="Validatable{T}"/>object property pertains to, and therefore is the target Type for the <see cref="AbstractValidator{T}"/>.</typeparam> /// <param name="validator">The Fluent <see cref="AbstractValidator{T}"/> instance.</param> /// <param name="validatableObj">The <see cref="Validatable{T}"/>object for which to retrieve ValidationRules for.</param> /// <returns>A List of IValidationRule relevant to the <see cref="Validatable{T}"/>object.</returns> public static List <IValidationRule> GetRulesFor <T>(this AbstractValidator <T> validator, IValidity validatableObj) { var descriptor = validator.CreateDescriptor(); return(descriptor.GetRulesForMember(validatableObj.ClassPropertyName).ToList()); }