Adding Generic RemoveAll<T> for ICollection<T> instances to CollectionUtils.

This commit is contained in:
gcaprio
2009-01-06 17:33:59 +00:00
parent 46ad783c09
commit 4ec8d36525

View File

@@ -129,8 +129,31 @@ namespace Spring.Util.Generic
}
return contains;
}
#endregion
/// <summary>
/// Removes all the elements from the target collection that are contained in the source collection.
/// </summary>
/// <param name="targetCollection">Collection where the elements will be removed.</param>
/// <param name="sourceCollection">Elements to remove from the target collection.</param>
public static void RemoveAll<T>(ICollection<T> targetCollection, ICollection<T> sourceCollection)
{
if (targetCollection == null)
{
throw new ArgumentNullException("targetCollection", "Collection cannot be null.");
}
if (sourceCollection == null)
{
throw new ArgumentNullException("sourceCollection", "Collection cannot be null.");
}
foreach (T element in sourceCollection)
{
if (targetCollection.Contains(element))
{
targetCollection.Remove(element);
}
}
}
#endregion
}
}
#endif