Esempio n. 1
0
 /// <summary>
 /// Coalesce the given string with the given mode using the given fallback.
 /// </summary>
 /// <param name="input"></param>
 /// <param name="fallback"></param>
 /// <param name="mode"></param>
 /// <returns></returns>
 public static string Coalesce(this string input, string fallback, StringCoalesceMode mode)
 {
     switch (mode)
     {
         case StringCoalesceMode.Null:
             return input ?? fallback;
         case StringCoalesceMode.NullOrEmpty:
             return string.IsNullOrEmpty(input) ? fallback : input;
         default:
             return string.IsNullOrWhiteSpace(input) ? fallback : input;
     }
 }
 /// <summary>
 /// Coalesce the given string with the given mode using the given fallback.
 /// </summary>
 /// <param name="input"></param>
 /// <param name="fallback"></param>
 /// <param name="mode"></param>
 /// <returns></returns>
 public static string Coalesce(this string input, string fallback, StringCoalesceMode mode) {
     switch (mode) {
         case StringCoalesceMode.Null :
             return input ?? fallback;
         case StringCoalesceMode.NullOrEmpty:
             return string.IsNullOrEmpty(input) ? fallback : input;
         case StringCoalesceMode.NullOrBlank:
             return string.IsNullOrWhiteSpace(input) ? fallback : input;
         default:
             throw new ArgumentOutOfRangeException("mode");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Coalesce the given string with the given mode using the given fallback.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="fallback"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static string Coalesce(this string input, string fallback, StringCoalesceMode mode)
        {
            switch (mode)
            {
            case StringCoalesceMode.Null:
                return(input ?? fallback);

            case StringCoalesceMode.NullOrEmpty:
                return(string.IsNullOrEmpty(input) ? fallback : input);

            case StringCoalesceMode.NullOrBlank:
                return(string.IsNullOrWhiteSpace(input) ? fallback : input);

            default:
                throw new ArgumentOutOfRangeException("mode");
            }
        }