Created
August 28, 2016 17:37
-
-
Save kmorcinek/4b2bebde7be759a6805e5c3de8da43ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public static class CollectionExtensions | |
{ | |
public static void RemoveAll<T>(this ICollection<T> @this, Func<T, bool> predicate) | |
{ | |
List<T> list = @this as List<T>; | |
if (list != null) | |
{ | |
list.RemoveAll(new Predicate<T>(predicate)); | |
} | |
else | |
{ | |
List<T> itemsToDelete = @this | |
.Where(predicate) | |
.ToList(); | |
foreach (var item in itemsToDelete) | |
{ | |
@this.Remove(item); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment