Beispiel #1
0
        /// <inheritdoc />
        public IEnumerable <Message> Validate(IPropertyContainer propertyContainer)
        {
            Message[] messages1 = FirstRule.Validate(propertyContainer).ToArray();
            Message[] messages2 = LastRule.Validate(propertyContainer).ToArray();

            // Rule1 true; Rule2 true => true
            // Rule1 true; Rule2 false => true
            // Rule1 false; Rule2 true => true
            // Rule1 false; Rule2 false => false
            if (messages1.Length > 0 && messages2.Length > 0)
            {
                // messages1.Length > 0 && messages2.Length > 0 => OR rule failed.
                string message1 = messages1.Select(message => message.FormattedMessage).FormatAsTuple(startSymbol: "[", endSymbol: "]");
                string message2 = messages2.Select(message => message.FormattedMessage).FormatAsTuple(startSymbol: "[", endSymbol: "]");

                yield return(new Message($"{message1} or {message2}", severity: MessageSeverity.Error));
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public IEnumerable <Message> Validate(IPropertyContainer propertyContainer)
        {
            foreach (var message in FirstRule.Validate(propertyContainer))
            {
                yield return(message);

                if (BreakOnFirstError)
                {
                    yield break;
                }
            }

            foreach (var message in LastRule.Validate(propertyContainer))
            {
                yield return(message);

                if (BreakOnFirstError)
                {
                    yield break;
                }
            }
        }