/// <summary> /// Validates the property. /// </summary> /// <param name="value">The value to validate.</param> /// <param name="validationContext">The context that describes the property to validate.</param> /// <param name="validationResults">A collection to hold each failed validation.</param> /// <returns>True if the property validates; otherwise, false.</returns> public virtual bool TryValidateProperty( object value, IValidationContext validationContext, ICollection<IValidationResult> validationResults ) { Arg.NotNull( validationContext, nameof( validationContext ) ); ValidationContext context; if ( !validationContext.TryGetService( out context ) ) return true; var results = new List<ValidationResult>(); var valid = Validator.TryValidateProperty( value, context, results ); if ( validationResults != null ) validationResults.AddRange( results.Select( r => new ValidationResultAdapter( r ) ) ); return valid; }
/// <summary> /// Determines whether the specified object is valid using the validation context. /// </summary> /// <param name="instance">The object to validate.</param> /// <param name="validationContext">The context that describes the object to validate.</param> public virtual void ValidateObject( object instance, IValidationContext validationContext ) { Arg.NotNull( instance, nameof( instance ) ); Arg.NotNull( validationContext, nameof( validationContext ) ); ValidationContext context; if ( validationContext.TryGetService( out context ) ) Validator.ValidateObject( instance, context ); }
/// <summary> /// Validates the property. /// </summary> /// <param name="value">The value to validate.</param> /// <param name="validationContext">The context that describes the property to validate.</param> public virtual void ValidateProperty( object value, IValidationContext validationContext ) { Arg.NotNull( validationContext, nameof( validationContext ) ); ValidationContext context; if ( validationContext.TryGetService( out context ) ) Validator.ValidateProperty( value, context ); }