| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Collections.ObjectModel; |
| | 4 | | using System.Text; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | namespace MUNity.Extensions.ObservableCollectionExtensions |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Extension methods that allow to work with observableCollections like linq. |
| | 11 | | /// </summary> |
| | 12 | | public static class ObservableCollectionTools |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Removes all entries with the given Predicate. |
| | 16 | | /// </summary> |
| | 17 | | /// <typeparam name="T"></typeparam> |
| | 18 | | /// <param name="collection"></param> |
| | 19 | | /// <param name="predicate"></param> |
| | 20 | | public static int RemoveAll<T>(this ObservableCollection<T> collection, Func<T, bool> predicate) |
| 0 | 21 | | { |
| 0 | 22 | | var toDelete = collection.Where(predicate).ToList(); |
| 0 | 23 | | int count = toDelete.Count; |
| 0 | 24 | | foreach(var deleteMe in toDelete) |
| 0 | 25 | | { |
| 0 | 26 | | collection.Remove(deleteMe); |
| 0 | 27 | | } |
| 0 | 28 | | toDelete.Clear(); |
| 0 | 29 | | return count; |
| 0 | 30 | | } |
| | 31 | | } |
| | 32 | | } |