Пример #1
0
        /// <summary>
        /// Main validation method with default handling of
        /// validation outcome: throw VaælidationException.
        /// </summary>
        public static void ValidateValue <TValue>(
            TValue value,
            Func <TValue, ValidationOutcome> validator)
        {
            ValidationOutcome vo = validator(value);

            if (!vo.Valid)
            {
                throw new ValidationException(vo.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Main validation method: If the validation
        /// finds errors, the specified action is executed.
        /// </summary>
        /// <typeparam name="TValue">
        /// Type of value subjected to validation
        /// </typeparam>
        /// <param name="value">
        /// Actual value subjected to validation
        /// </param>
        /// <param name="validator">
        /// Function performing the actual validation
        /// </param>
        /// <param name="outcomeHandler">
        /// Function handling the outcome in case
        /// the validation found an error
        /// </param>
        public static void ValidateValue <TValue>(
            TValue value,
            Func <TValue, ValidationOutcome> validator,
            Action <ValidationOutcome> outcomeHandler)
        {
            ValidationOutcome vo = validator(value);

            if (!vo.Valid)
            {
                outcomeHandler(vo);
            }
        }