Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/IListExtensions.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.2 KB
Line 
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}
Note: See TracBrowser for help on using the repository browser.