PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/Main/src/DynamicDataDisplay/Common/Auxiliary/IListExtensions.cs

#
C# | 52 lines | 47 code | 5 blank | 0 comment | 0 complexity | bc5db742b0de3ae9988a2b96a3d39744 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5
 6namespace 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}