Ejemplo n.º 1
0
        public void Validate(IValidationContext <T> validationContext)
        {
            if (_checkCondition?.Invoke(validationContext.InstanceForValidation) == false)
            {
                return;
            }

            var propertyValidationContext = new PropertyValidationContext <T, TProperty>(_propertyExpression, validationContext);

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var propertyValidationStep in _validationSteps)
            {
                if (!propertyValidationStep.Validate(propertyValidationContext) &&
                    validationContext.BreakRuleValidationAfterFirstFailedValidation)
                {
                    break;
                }
            }

            if (!propertyValidationContext.Faults.Any())
            {
                return;
            }

            validationContext.AddFaults(HasFaultMessage
                ? new[] { new ValidationFault(propertyValidationContext.PropertyName, FaultMessage) }
                : propertyValidationContext.Faults);
        }