Пример #1
0
        public IValitResult Validate(TObject @object)
        {
            @object.ThrowIfNull();

            var property = _propertySelector(@object);
            var hasAllConditionsFulfilled = true;

            foreach (var condition in _conditions)
            {
                hasAllConditionsFulfilled &= condition(@object);
            }

            var isSatisfied = _predicate?.Invoke(property) != false;

            return(!hasAllConditionsFulfilled || isSatisfied ? ValitResult.Success : ValitResult.Fail(_errors.ToArray()));
        }
Пример #2
0
        public IValitResult Validate(TObject @object)
        {
            @object.ThrowIfNull();

            var property = _propertySelector.Compile().Invoke(@object);
            var hasAllConditionsFulfilled = true;

            foreach (var condition in _conditions)
            {
                hasAllConditionsFulfilled &= condition(@object);
            }

            var isSatisfied = _predicate?.Invoke(property) != false;
            var errors      = _errors.Where(e => !e.IsDefault).Any() ? _errors.Where(e => !e.IsDefault) : _errors;

            return(!hasAllConditionsFulfilled || isSatisfied ? ValitResult.Success : ValitResult.Fail(errors.ToArray()));
        }