ArgumentCheck.IsNullorWhiteSpace C# (CSharp) Method

IsNullorWhiteSpace() public static method

Checks if a value is string or any other object if it is string it checks for nullorwhitespace otherwhise it checks for null only
public static IsNullorWhiteSpace ( item, string nameOfTheArgument = "" ) : void
item The item you want to check
nameOfTheArgument string Name of the argument
return void
        public static void IsNullorWhiteSpace<T>(T item, string nameOfTheArgument = "")
        {
            Type type = typeof(T);
            if (type == typeof(string) ||
                type == typeof(String))
            {
                if (string.IsNullOrWhiteSpace(item as string))
                {
                    throw new ArgumentException(nameOfTheArgument + " is null or Whitespace");
                }
            }
            else
            {
                if (item == null)
                {
                    throw new ArgumentException(nameOfTheArgument + " is null");
                }
            }
        }
    }

Usage Example

 /// <summary>
 /// Changes all elements of IEnumerable by the change function
 /// </summary>
 /// <param name="enumerable">The enumerable where you want to change stuff</param>
 /// <param name="change">The way you want to change the stuff</param>
 /// <returns>An IEnumerable with all changes applied</returns>
 public static IEnumerable <T> Change <T>(this IEnumerable <T> enumerable, Func <T, T> change)
 {
     ArgumentCheck.IsNullorWhiteSpace(enumerable, "enumerable");
     ArgumentCheck.IsNullorWhiteSpace(change, "change");
     foreach (var item in enumerable)
     {
         yield return(change(item));
     }
 }
All Usage Examples Of ArgumentCheck::IsNullorWhiteSpace
ArgumentCheck