/// <summary>
        /// Checks whether the given value is not null and not an <see cref="String.Empty"/> string.
        /// An exception is thrown otherwise.
        /// </summary>
        /// <param name="validator">The <see cref="ConditionValidator{T}"/> that holds the value that has to be checked.</param>
        /// <returns>The specified <paramref name="validator"/> instance.</returns>
        /// <exception cref="ArgumentException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is <see cref="String.Empty"/>, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is null or empty, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Requires{T}(T,string)">Requires</see> extension method.</exception>
        /// <exception cref="PostconditionException">Thrown when the <see cref="ConditionValidator{T}.Value">Value</see> of the specified <paramref name="validator"/> is null or empty, while the specified <paramref name="validator"/> is created using the <see cref="Condition.Ensures{T}(T,string)">Ensures</see> extension method.</exception>
        public static ConditionValidator <string> IsNotNullOrEmpty(this ConditionValidator <string> validator)
        {
            bool valueIsInvalid = String.IsNullOrEmpty(validator.Value);

            if (valueIsInvalid)
            {
                Throw.ValueShouldNotBeNullOrAnEmptyString(validator, null);
            }

            return(validator);
        }
Beispiel #2
0
 private static string GetFormattedConditionMessage <T>(
     ConditionValidator <T> validator,
     string resourceKey,
     string conditionDescription, params object[] resourceFormatArguments)
 {
     if (conditionDescription != null)
     {
         return(FormatConditionDescription(validator, conditionDescription));
     }
     else
     {
         return(SR.GetString(resourceKey, resourceFormatArguments));
     }
 }
Beispiel #3
0
 private static string FormatConditionDescription <T>(ConditionValidator <T> validator,
                                                      string conditionDescription)
 {
     try
     {
         return(String.Format(CultureInfo.CurrentCulture, conditionDescription ?? String.Empty,
                              validator.ArgumentName));
     }
     catch (FormatException)
     {
         // We catch a FormatException. This code should only throw exceptions generated by the
         // validator.BuildException method. Throwing another exception would confuse the user and
         // would make debugging harder. When the user supplied an unformattable description, we simply
         // use the unformatted description as condition.
         return(conditionDescription);
     }
 }