Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
7 | {
|
---|
8 | public static class IListExtensions
|
---|
9 | {
|
---|
10 | public static void AddMany<T>(this IList<T> collection, IEnumerable<T> addingItems)
|
---|
11 | {
|
---|
12 | foreach (var item in addingItems)
|
---|
13 | {
|
---|
14 | collection.Add(item);
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public static void AddMany<T>(this IList<T> collection, params T[] children)
|
---|
19 | {
|
---|
20 | foreach (var child in children)
|
---|
21 | {
|
---|
22 | collection.Add(child);
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static void RemoveAllOfType<T>(this IList<T> collection, Type type)
|
---|
27 | {
|
---|
28 | var children = collection.Where(el => type.IsAssignableFrom(el.GetType())).ToArray();
|
---|
29 | foreach (var child in children)
|
---|
30 | {
|
---|
31 | collection.Remove((T)child);
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static void RemoveAll<T, TDelete>(this IList<T> collection)
|
---|
36 | {
|
---|
37 | var children = collection.OfType<TDelete>().ToArray();
|
---|
38 | foreach (var child in children)
|
---|
39 | {
|
---|
40 | collection.Remove((T)(object)child);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public static void RemoveAll<T>(this IList<T> collection, params T[] elements)
|
---|
45 | {
|
---|
46 | foreach (var item in elements)
|
---|
47 | {
|
---|
48 | collection.Remove(item);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.