view MetroWpf/MetroWpf.Framework/Extensions/CollectionExtensions.cs @ 27:96fdf58e05b4

Server working with sockets and rabbitmq
author adminsh@apollo
date Wed, 21 Mar 2012 19:00:59 +0000
parents 060f02cd4591
children
line wrap: on
line source

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
  }
}