/// <inheritdoc /> public void AddValidation(AbstractValidation <T> validation) { if (!Validations.Any(a => a.Name == validation.Name)) { _validations.Add(item: validation); } }
/// <summary> /// Contructor with the cacheKey, originalValue, valid and the validation /// </summary> /// <param name="cacheKey">The key of the Cache-Entry</param> /// <param name="originalValue">The original value</param> /// <param name="valid">The result</param> /// <param name="validation">The validation</param> public CacheItemUsedEventArgs( string cacheKey, object originalValue, bool valid, AbstractValidation <T> validation) { CacheKey = cacheKey; OriginalValue = originalValue; Valid = valid; Validation = validation; }
private ValidationResponse CreateValidationResponse( bool valid, AbstractValidation <T> validation, T value) { return(new ValidationResponse( type: valid?ValidationResponseType.Success: ValidationResponseType.Error, name: validation.Name, message: valid ? validation.MessageOnSuccess : validation.MessageOnError, originalValue: validation.OriginalValue(arg: value))); }
/// <summary> /// Adds a new <see cref="AbstractValidation{T}"/> to the <see cref="Validator{T}" /> /// </summary> /// <typeparam name="T">The Type to validate</typeparam> /// <param name="validator">The validator</param> /// <param name="validation">The validation to add</param> /// <returns>Returns the Instance of <see cref="Validator{T}"/></returns> /// <exception cref="InvalidOperationException">Occurs if the instance of <see cref="Validator{T}"/> is null</exception> public static Validator <T> Add <T>( this Validator <T> validator, AbstractValidation <T> validation) { if (validator == null) { throw new InvalidOperationException(message: "Validator is null"); } validator.AddValidation(validation: validation); return(validator); }