using System; using System.Collections.Generic; namespace Abp.Collections.Extensions { /// /// Extension methods for Collections. /// public static class CollectionExtensions { /// /// Checks whatever given collection object is null or has no item. /// public static bool IsNullOrEmpty(this ICollection source) { return source == null || source.Count <= 0; } /// /// Adds an item to the collection if it's not already in the collection. /// /// Collection /// Item to check and add /// Type of the items in the collection /// Returns True if added, returns False if not. public static bool AddIfNotContains(this ICollection source, T item) { if (source == null) { throw new ArgumentNullException("source"); } if (source.Contains(item)) { return false; } source.Add(item); return true; } } }