comparison MetroWpf/MetroWpf.Framework/Extensions/CollectionExtensions.cs @ 15:060f02cd4591

Initial commit, pre airport work
author stevenh7776 stevenhollidge@hotmail.com
date Mon, 12 Mar 2012 23:05:21 +0800
parents
children
comparison
equal deleted inserted replaced
14:741981715d94 15:060f02cd4591
1 using System;
2 using System.Collections.Generic;
3
4 namespace MetroWpf
5 {
6 public static class CollectionExtensions
7 {
8 #region · Extensions ·
9
10 public static bool AddUnique<T>(this ICollection<T> collection, T value)
11 {
12 if (!collection.Contains(value))
13 {
14 collection.Add(value);
15 return true;
16 }
17
18 return false;
19 }
20
21 public static int AddRangeUnique<T>(this ICollection<T> collection, IEnumerable<T> values)
22 {
23 var count = 0;
24
25 foreach (var value in values)
26 {
27 if (collection.AddUnique(value))
28 {
29 count++;
30 }
31 }
32
33 return count;
34 }
35
36 public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> values)
37 {
38 foreach (T value in values)
39 {
40 collection.Add(value);
41 }
42 }
43
44 #endregion
45 }
46 }