diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf.Framework/Extensions/CollectionExtensions.cs	Mon Mar 12 23:05:21 2012 +0800
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+
+namespace MetroWpf
+{
+  public static class CollectionExtensions
+  {
+    #region · Extensions ·
+
+    public static bool AddUnique<T>(this ICollection<T> collection, T value)
+    {
+      if (!collection.Contains(value))
+      {
+        collection.Add(value);
+        return true;
+      }
+
+      return false;
+    }
+
+    public static int AddRangeUnique<T>(this ICollection<T> collection, IEnumerable<T> values)
+    {
+      var count = 0;
+
+      foreach (var value in values)
+      {
+        if (collection.AddUnique(value))
+        {
+          count++;
+        }
+      }
+
+      return count;
+    }
+
+    public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> values)
+    {
+      foreach (T value in values)
+      {
+        collection.Add(value);
+      }
+    }
+
+    #endregion
+  }
+}
\ No newline at end of file