mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Volo.Collections.Generic
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for Collections.
|
|
/// </summary>
|
|
public static class CollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Checks whatever given collection object is null or has no item.
|
|
/// </summary>
|
|
public static bool IsNullOrEmpty<T>([CanBeNull] this ICollection<T> source)
|
|
{
|
|
return source == null || source.Count <= 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds an item to the collection if it's not already in the collection.
|
|
/// </summary>
|
|
/// <param name="source">Collection</param>
|
|
/// <param name="item">Item to check and add</param>
|
|
/// <typeparam name="T">Type of the items in the collection</typeparam>
|
|
/// <returns>Returns True if added, returns False if not.</returns>
|
|
public static bool AddIfNotContains<T>([NotNull] this ICollection<T> source, T item)
|
|
{
|
|
Check.NotNull(source, nameof(source));
|
|
|
|
if (source.Contains(item))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
source.Add(item);
|
|
return true;
|
|
}
|
|
}
|
|
}
|