Ejemplo n.º 1
0
        /// <summary>
        /// Copies the properties of a given <see cref="ValidationResult"/> object to the <paramref name="element"/>.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="element">The element.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if either <paramref name="element"/> or <paramref name="result"/> are <see langword="null"/>.
        /// </exception>
        public static void CopyTo(
            this ValidationResult result,
            ValidationFaultElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }

            element.Message       = result.Message;
            element.Key           = result.Key;
            element.Tag           = result.Tag;
            element.ValidatorType = result.Validator?.GetType().Name;

            if (result.Target != null)
            {
                Type targetType = result.Target as Type;

                element.TargetTypeName = targetType != null
                                            ? targetType.Name
                                            : result.Target.GetType().Name;
            }

            element.NestedValidationElements = new List <ValidationFaultElement>();
            result.NestedValidationResults.CopyTo(element.NestedValidationElements);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the specified detail.
        /// </summary>
        /// <param name="detail">The detail.</param>
        public void Add(
            ValidationFaultElement detail)
        {
            if (detail == null)
            {
                throw new ArgumentNullException(nameof(detail));
            }

            InternalDetails.Add(detail);
        }