| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Collections.Specialized;using System.Linq;namespace MECF.Framework.UI.Client.ClientBase.Collections{    /// <summary>     /// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.     /// </summary>     /// <typeparam name="T"></typeparam>     public class ObservableRangeCollection<T> : ObservableCollection<T>    {        #region Constructors        /// <summary>         /// Initializes a new instance of the System.Collections.ObjectModel.ObservableCollection(Of T) class.         /// </summary>         public ObservableRangeCollection()        {        }        /// <summary>         /// Initializes a new instance of the System.Collections.ObjectModel.ObservableCollection(Of T) class that contains elements copied from the specified collection.         /// </summary>         /// <param name="collection">collection: The collection from which the elements are copied.</param>         /// <exception cref="System.ArgumentNullException">The collection parameter cannot be null.</exception>         public ObservableRangeCollection(IEnumerable<T> collection)            : base(collection)        {        }        #endregion                /// <summary>         /// Adds the elements of the specified collection to the end of the ObservableCollection(Of T).         /// </summary>         public virtual void AddRange(IEnumerable<T> collection)        {            if (collection == null) throw new ArgumentNullException(nameof(collection));            var startIndex = Count;            var enumerable = collection.ToList();            foreach (var i in enumerable)                Items.Add(i);            OnCollectionChanged(                new NotifyCollectionChangedEventArgs(                    NotifyCollectionChangedAction.Reset));        }        /// <summary>         /// Removes the first occurence of each item in the specified collection from ObservableCollection(Of T).         /// </summary>         public virtual void RemoveRange(IEnumerable<T> collection)        {            if (collection == null) throw new ArgumentNullException(nameof(collection));            foreach (var i in collection)                Items.Remove(i);            OnCollectionChanged(                new NotifyCollectionChangedEventArgs(                    NotifyCollectionChangedAction.Reset));        }        /// <summary>         /// Clears the current collection and replaces it with the specified item.         /// </summary>         public virtual void Replace(T item)        {            ReplaceRange(new[] {item});        }        /// <summary>         /// Clears the current collection and replaces it with the specified collection.         /// </summary>         public void ReplaceRange(IEnumerable<T> collection)        {            if (collection == null) throw new ArgumentNullException(nameof(collection));            Items.Clear();            foreach (var i in collection) Items.Add(i);            OnCollectionChanged(                new NotifyCollectionChangedEventArgs(                    NotifyCollectionChangedAction.Reset));        }    }}
 |