| | | 1 | | // ReSharper disable once CheckNamespace |
| | | 2 | | namespace Elsa.Extensions; |
| | | 3 | | |
| | | 4 | | /// <summary> |
| | | 5 | | /// Provides extension methods for collections. |
| | | 6 | | /// </summary> |
| | | 7 | | public static class CollectionExtensions |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Adds a range of items to a collection. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <param name="target">The target collection.</param> |
| | | 13 | | /// <param name="source">The source collection.</param> |
| | | 14 | | /// <typeparam name="T">The type of items in the collection.</typeparam> |
| | | 15 | | public static void AddRange<T>(this ICollection<T> target, IEnumerable<T> source) |
| | | 16 | | { |
| | 4956 | 17 | | foreach (var item in source) target.Add(item); |
| | 618 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Adds a range of items to a collection. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="target">The target collection.</param> |
| | | 24 | | /// <param name="source">The source collection.</param> |
| | | 25 | | /// <typeparam name="T">The type of items in the collection.</typeparam> |
| | 0 | 26 | | public static void AddRange<T>(this ICollection<T> target, params T[] source) => AddRange(target, source.AsEnumerabl |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Removes all items from a collection that match the specified predicate. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="collection">The collection.</param> |
| | | 32 | | /// <param name="predicate">The predicate.</param> |
| | | 33 | | /// <typeparam name="T">The type of items in the collection.</typeparam> |
| | | 34 | | public static void RemoveWhere<T>(this ICollection<T> collection, Func<T, bool> predicate) |
| | | 35 | | { |
| | 6612 | 36 | | var itemsToRemove = collection.Where(predicate).ToList(); |
| | 15555 | 37 | | foreach (var item in itemsToRemove) collection.Remove(item); |
| | 6612 | 38 | | } |
| | | 39 | | } |