public static bool SafeAny<T>(this IEnumerable<T> collection)
 {
     return collection?.Any() ?? false;
 }
Beispiel #2
0
 /// <summary>
 /// Checks if a collection is null or empty duh!
 /// </summary>
 /// <typeparam name="T">Type</typeparam>
 /// <param name="items">collection</param>
 /// <returns></returns>
 public static bool IsNullOrEmpty <T>(this IEnumerable <T> items)
 {
     return(items == null || !items.Any());
 }
Beispiel #3
0
 /// <summary>
 /// Check if collection has any items.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public static bool HasItems <T>(this IEnumerable <T> source, Func <T, bool> predicate)
 {
     return(source?.Any(predicate) == true);
 }
 //public static bool HasElements<T>(this IEnumerable<T> source) => source == null || !source.Any();
 public static bool HasAnyItems <T>(this IEnumerable <T> source) => source?.Any() ?? false;
Beispiel #5
0
 /// <summary>
 /// Check if collection has any items.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public static bool HasItems <T>(this IEnumerable <T> source)
 {
     return(source?.Any() == true);
 }
Beispiel #6
0
 /// <summary>
 /// Checks if source collection constains part of specified string.
 /// </summary>
 public static bool ContainsPartOfString(this IEnumerable <string> source, string value, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
 {
     return(source?.Any(a => value?.IndexOf(a, comparison) >= 0) == true);
 }
Beispiel #7
0
 /// <summary>
 /// Checks if source collection constains specified string completely.
 /// </summary>
 public static bool ContainsString(this IEnumerable <string> source, string value, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
 {
     return(source?.Any(a => a?.Equals(value, comparison) == true) == true);
 }
Beispiel #8
0
 /// <summary>
 /// Checks if collection has any non-empty string items.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static bool HasNonEmptyItems(this IEnumerable <string> source)
 {
     return(source?.Any(a => !string.IsNullOrEmpty(a)) == true);
 }
 /// <summary>
 /// Determines whether collection is null or empty.
 /// </summary>
 public static bool IsNullOrEmpty <T>(this IEnumerable <T> collection)
 {
     return(collection == null || !collection.Any());
 }