Exemplo n.º 1
0
        /// <summary>Returns the first value that is not <see langword="null"/>.</summary>
        /// <param name="options">The options to use.</param>
        /// <param name="values">The values to examine.</param>
        /// <returns>The first value that is not <see langword="null"/>.  If all values are <see langword="null"/> then
        /// <see langword="null"/> is returned.</returns>
        public static string Coalesce(StringCoalesceOptions options, IEnumerable <string> values)
        {
            values = values ?? new string[0];

            IEnumerable <string> query;

            if (options.HasFlag(StringCoalesceOptions.SkipEmpty))
            {
                query = values.Where(x => !String.IsNullOrEmpty(x));
            }
            else
            {
                query = values.Where(x => x != null);
            }

            return(query.FirstOrDefault());
        }
Exemplo n.º 2
0
 /// <summary>Returns the first value that is not <see langword="null"/>.</summary>
 /// <param name="options">The options to use.</param>
 /// <param name="values">The values to examine.</param>
 /// <returns>The first value that is not <see langword="null"/>.  If all values are <see langword="null"/> then
 /// <see langword="null"/> is returned.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="values"/> is <see langword="null"/>.</exception>
 public static string Coalesce(StringCoalesceOptions options, params string[] values)
 {
     return(Coalesce(options, values as IEnumerable <string>));
 }