Example #1
0
        /// <summary>
        /// Allocates a new validation state with the specified error added to existing state
        /// </summary>
        /// <param name="existing">Existing context state that the new state will be based on</param>
        /// <param name="error">An error to return</param>
        public ValidState(ValidState existing, Exception error)
        {
            if (!existing.IsAssigned)
            {
                throw new CallGuardException(nameof(ValidState) + ".ctor", nameof(existing), "Unassigned");
            }

            TargetName = existing.TargetName;
            Mode       = existing.Mode;
            Error      = ValidationBatchException.Concatenate(existing.Error, error);
            ErrorLimit = existing.ErrorLimit;
        }
Example #2
0
        /// <summary>
        /// Links two errors together into ValidationBatchException, creating a new instance if necessary.
        /// Both parameters can be null. A new instance is create only if existing exception is not null
        /// and is not of ValidationBatchException type, otherwise new exception is added to an existing batch instance.
        /// The method may return null if both exceptions are null.
        /// </summary>
        public static Exception Concatenate(Exception existingException, Exception newException)
        {
            if (existingException == null)
            {
                return(newException);
            }
            if (newException == null)
            {
                return(existingException);
            }

            var result = existingException as ValidationBatchException;

            if (result == null)
            {
                result = new ValidationBatchException(existingException);
            }

            result.Batch.Add(newException);

            return(result);
        }