using System;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace Volo.Collections.Generic
{
///
/// Extension methods for Collections.
///
public static class CollectionExtensions
{
///
/// Checks whatever given collection object is null or has no item.
///
public static bool IsNullOrEmpty([CanBeNull] 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([NotNull] this ICollection source, T item)
{
Check.NotNull(source, nameof(source));
if (source.Contains(item))
{
return false;
}
source.Add(item);
return true;
}
}
}