/// <summary> /// Initializes a new instance of the <see cref="ValidationContext{TEntity}"/> class. /// </summary> /// <param name="value">The entity value.</param> /// <param name="args">The <see cref="ValidationArgs"/>.</param> public ValidationContext(TEntity value, ValidationArgs args) { Beef.Check.NotNull(args, nameof(args)); Value = value; FullyQualifiedEntityName = args.FullyQualifiedEntityName; FullyQualifiedJsonEntityName = args.FullyQualifiedJsonEntityName; UseJsonNames = args.UseJsonNamesSelection; Config = args.Config; SelectedPropertyName = args.SelectedPropertyName; ShallowValidation = args.ShallowValidation; Messages.CollectionChanged += Messages_CollectionChanged; }
/// <summary> /// Adds an entity <see cref="ValidatorBase{TEntity}"/> with specified <see cref="ValidationArgs"/>. /// </summary> /// <typeparam name="TEntity">The entity <see cref="Type"/>.</typeparam> /// <typeparam name="TValidator">The validator <see cref="Type"/>.</typeparam> /// <param name="validator">The <see cref="ValidatorBase{TEntity}"/>.</param> /// <param name="value">The entity value.</param> /// <param name="args">An optional <see cref="ValidationArgs"/>.</param> /// <returns>The (this) <see cref="MultiValidator"/>.</returns> public MultiValidator Add <TEntity, TValidator>(ValidatorBase <TEntity> validator, TEntity value, ValidationArgs args) where TEntity : class where TValidator : ValidatorBase <TEntity> { _validators.Add(() => validator.Validate(value, args).Messages); return(this); }
/// <summary> /// Validate the entity value with specified <see cref="ValidationArgs"/>. /// </summary> /// <param name="value">The entity value.</param> /// <param name="args">An optional <see cref="ValidationArgs"/>.</param> /// <returns>The resulting <see cref="ValidationContext{TEntity}"/>.</returns> public virtual ValidationContext <TEntity> Validate(TEntity value, ValidationArgs args = null) { throw new NotSupportedException("Validate is not supported by this class."); }
/// <summary> /// Validate the entity value with specified <see cref="ValidationArgs"/>. /// </summary> /// <param name="value">The entity value.</param> /// <param name="args">An optional <see cref="ValidationArgs"/>.</param> /// <returns>The resulting <see cref="IValidationContext"/>.</returns> IValidationContext IValidator.Validate(object value, ValidationArgs args) { return(Validate((TEntity)value, args)); }
/// <summary> /// Validate the entity value with specified <see cref="ValidationArgs"/>. /// </summary> /// <param name="value">The entity value.</param> /// <param name="args">An optional <see cref="ValidationArgs"/>.</param> /// <returns>The resulting <see cref="IValidationContext"/>.</returns> async Task <IValidationContext> IValidator.ValidateAsync(object?value, ValidationArgs args) { return(await ValidateAsync((TEntity)value !, args).ConfigureAwait(false)); }