Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/29/09 02:33:57 (14 years ago)
Author:
swagner
Message:

Implemented IDisposable and unified extension capabilities for all observable collections (#819)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs

    r2574 r2575  
    6666      dict = new Dictionary<TKey, TItem>();
    6767      foreach (TItem item in collection)
    68         AddItem(item);
     68        dict.Add(GetKeyForItem(item), item);
     69      OnItemsAdded(collection);
    6970    }
    7071    protected ObservableKeyedCollectionBase(int capacity, IEqualityComparer<TKey> comparer) {
     
    7576      dict = new Dictionary<TKey, TItem>(comparer);
    7677      foreach (TItem item in collection)
    77         AddItem(item);
     78        dict.Add(GetKeyForItem(item), item);
     79      OnItemsAdded(collection);
    7880    }
    7981    #endregion
     
    150152
    151153    #region Manipulation
    152     protected virtual void AddItem(TItem item) {
     154    public void Add(TItem item) {
    153155      dict.Add(GetKeyForItem(item), item);
    154     }
    155     public void Add(TItem item) {
    156       AddItem(item);
    157156      OnItemsAdded(new TItem[] { item });
    158157    }
     
    160159      if (collection == null) throw new ArgumentNullException();
    161160      foreach (TItem item in collection)
    162         AddItem(item);
     161        dict.Add(GetKeyForItem(item), item);
    163162      OnItemsAdded(collection);
    164163    }
    165164
    166     protected virtual bool RemoveItem(TItem item) {
    167       return dict.Remove(GetKeyForItem(item));
    168     }
    169165    public bool Remove(TKey key) {
    170166      TItem item;
    171167      if (TryGetValue(key, out item)) {
    172         RemoveItem(item);
     168        dict.Remove(key);
    173169        OnItemsRemoved(new TItem[] { item });
    174170        return true;
     
    177173    }
    178174    public bool Remove(TItem item) {
    179       if (RemoveItem(item)) {
     175      if (dict.Remove(GetKeyForItem(item))) {
    180176        OnItemsRemoved(new TItem[] { item });
    181177        return true;
     
    187183      List<TItem> items = new List<TItem>();
    188184      foreach (TItem item in collection) {
    189         if (RemoveItem(item))
     185        if (dict.Remove(GetKeyForItem(item)))
    190186          items.Add(item);
    191187      }
     
    199195    }
    200196
    201     protected virtual void ClearItems() {
    202       dict.Clear();
    203     }
    204197    public void Clear() {
    205198      TItem[] items = dict.Values.ToArray();
    206       ClearItems();
     199      dict.Clear();
    207200      OnCollectionReset(new TItem[0], items);
    208201    }
Note: See TracChangeset for help on using the changeset viewer.