You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/MADE.Collections/CollectionExtensions.cs
+117Lines changed: 117 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,60 @@ namespace MADE.Collections
12
12
/// </summary>
13
13
publicstaticclassCollectionExtensions
14
14
{
15
+
/// <summary>
16
+
/// Adds the specified item to the collection based on the specified condition being true.
17
+
/// </summary>
18
+
/// <param name="collection">The collection to add the item to.</param>
19
+
/// <param name="item">The item to add.</param>
20
+
/// <param name="condition">The condition required to add the item.</param>
21
+
/// <typeparam name="T">The type of item within the collection.</typeparam>
22
+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
23
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
/// Removes the specified item from the collection based on the specified condition being true.
44
+
/// </summary>
45
+
/// <param name="collection">The collection to remove the item from.</param>
46
+
/// <param name="item">The item to remove.</param>
47
+
/// <param name="condition">The condition required to remove the item.</param>
48
+
/// <typeparam name="T">The type of item within the collection.</typeparam>
49
+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
50
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
@@ -114,6 +168,31 @@ public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> it
114
168
}
115
169
}
116
170
171
+
/// <summary>
172
+
/// Adds the specified collection of items to the collection based on the specified condition being true.
173
+
/// </summary>
174
+
/// <param name="collection">The collection to add the items to.</param>
175
+
/// <param name="itemsToAdd">The items to add.</param>
176
+
/// <param name="condition">The condition required to add the items.</param>
177
+
/// <typeparam name="T">The type of item within the collection.</typeparam>
178
+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/>, <paramref name="itemsToAdd"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
179
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
/// Removes the specified collection of items from the collection based on the specified condition being true.
232
+
/// </summary>
233
+
/// <param name="collection">The collection to remove the items from.</param>
234
+
/// <param name="itemsToRemove">The items to remove.</param>
235
+
/// <param name="condition">The condition required to remove the items.</param>
236
+
/// <typeparam name="T">The type of item within the collection.</typeparam>
237
+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/>, <paramref name="itemsToRemove"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
238
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
239
+
publicstaticvoidRemoveRangeIf<T>(
240
+
thisICollection<T>collection,
241
+
IEnumerable<T>itemsToRemove,
242
+
Func<bool>condition)
243
+
{
244
+
if(condition==null)
245
+
{
246
+
thrownewArgumentNullException(nameof(condition));
247
+
}
248
+
249
+
if(condition())
250
+
{
251
+
collection.RemoveRange(itemsToRemove);
252
+
}
253
+
}
254
+
151
255
/// <summary>
152
256
/// Determines whether two collections are equivalent, containing all the same items with no regard to order.
153
257
/// </summary>
@@ -219,6 +323,7 @@ public static IEnumerable<T> TakeFrom<T>(this List<T> list, int startingIndex, i
219
323
/// <param name="action">
220
324
/// The action to perform.
221
325
/// </param>
326
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
@@ -262,6 +367,7 @@ public static int InsertAtPotentialIndex<T>(this IList<T> source, T value, Func<
262
367
/// <param name="predicate">The action to run to determine the position of the item based on the provided <paramref name="value"/> and an item in the collection.</param>
263
368
/// <typeparam name="T">The type of items in the collection.</typeparam>
264
369
/// <returns>The potential index of the item.</returns>
370
+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
0 commit comments