예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="And{T}"/> class.
        /// </summary>
        /// <param name="rule1">First rule.</param>
        /// <param name="rule2">Second rule.</param>
        /// <param name="breakOnFirstError">Value indicating whether rule should break on first error.</param>
        public And(IValidationRule <T> rule1, IValidationRule <T> rule2, bool breakOnFirstError = false)
        {
            FirstRule = rule1.AssertArgumentNotNull(nameof(rule1));
            LastRule  = rule2.AssertArgumentNotNull(nameof(rule2));

            Property          = rule1.Property;
            BreakOnFirstError = breakOnFirstError;
        }
예제 #2
0
        /// <summary>
        /// Adds untyped validation to property metadata <see cref="IPropertyValidationRules"/>.
        /// </summary>
        /// <param name="property">Source property.</param>
        /// <param name="validationRule">Validation rule.</param>
        /// <returns>The same property.</returns>
        public static IProperty AddValidation(this IProperty property, IValidationRule validationRule)
        {
            property.AssertArgumentNotNull(nameof(property));
            validationRule.AssertArgumentNotNull(nameof(validationRule));

            return(property.ConfigureMetadata <IProperty, IPropertyValidationRules>(
                       createMetadata: CreatePropertyValidationRules,
                       configureMetadata: propertyValidation => propertyValidation.AddRule(validationRule)));
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AndBuilder{T}"/> class.
 /// </summary>
 /// <param name="firstRule">The first rule.</param>
 /// <param name="breakOnFirstError">Value indicating whether rule should break on first error.</param>
 public AndBuilder(IValidationRule <T> firstRule, bool breakOnFirstError = false)
 {
     FirstRule         = firstRule.AssertArgumentNotNull(nameof(firstRule));
     BreakOnFirstError = breakOnFirstError;
 }
예제 #4
0
        /// <inheritdoc />
        public And <T> CombineWith(IValidationRule <T> nextRule)
        {
            nextRule.AssertArgumentNotNull(nameof(nextRule));

            return(new And <T>(FirstRule, nextRule, BreakOnFirstError));
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Or"/> class.
 /// </summary>
 /// <param name="rule1">First rule.</param>
 /// <param name="rule2">Second rule.</param>
 public Or(IValidationRule rule1, IValidationRule rule2)
 {
     FirstRule = rule1.AssertArgumentNotNull(nameof(rule1));
     LastRule  = rule2.AssertArgumentNotNull(nameof(rule2));
 }