/// <summary>
        /// Validates that the parameter contains the specific <paramref name="value" />. Otherwise, an <see cref="ArgumentException" /> is thrown.
        /// </summary>
        /// <param name="validator">The <see cref="ParameterValidator{TParameter}" />.</param>
        /// <param name="value">The value the parameter must contain.</param>
        /// <returns>The same instance of <see cref="ParameterValidator{TParameter}" />.</returns>
        /// <exception cref="ArgumentException">Thrown when the parameter value does not contain <paramref name="value" />.</exception>
        public static ParameterValidator <string> Contains(this ParameterValidator <string> validator, string value)
        {
            if (validator.Value == null || value == null)
            {
                return(validator);
            }

            string exceptionMessage = string.Format(ExceptionMessages.VALUE_MUST_CONTAIN, value);

            return(validator.Contains(value, exceptionMessage));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates that the parameter contains <paramref name="value" />. Otherwise an <see cref="ArgumentException" /> is thrown.
        /// </summary>
        /// <typeparam name="TParameter">The parameter type.</typeparam>
        /// <typeparam name="TValue">The type the parameter value contains.</typeparam>
        /// <param name="validator">The <see cref="ParameterValidator{TParameter}" />.</param>
        /// <param name="value">The value the parameter must contain.</param>
        /// <returns>The same instance of <see cref="ParameterValidator{TParameter}" />.</returns>
        /// <exception cref="ArgumentException">Occurs when the parameter does not contain <paramref name="value" />.</exception>
        public static ParameterValidator <TParameter> Contains <TParameter, TValue>(this ParameterValidator <TParameter> validator, TValue value)
            where TParameter : IEnumerable <TValue>
        {
            if (value != null)
            {
                string exceptionMessage = string.Format(ExceptionMessages.VALUE_MUST_CONTAIN, value.ToString());

                return(validator.Contains(value, exceptionMessage));
            }

            return(validator);
        }