Changeset 2618


Ignore:
Timestamp:
01/09/10 03:22:58 (10 years ago)
Author:
swagner
Message:

Worked on HeuristicLab.Collections (#819)

  • removed implementation of IDisposable
  • added read-only wrappers
Location:
trunk/sources/HeuristicLab.Collections/3.3
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj

    r2574 r2618  
    4949  </ItemGroup>
    5050  <ItemGroup>
     51    <Compile Include="ReadOnlyObservableKeyedCollection.cs">
     52      <SubType>Code</SubType>
     53    </Compile>
     54    <Compile Include="ReadOnlyObservableList.cs" />
     55    <Compile Include="ReadOnlyObservableDictionary.cs" />
     56    <Compile Include="ReadOnlyObservableCollection.cs" />
    5157    <Compile Include="IObservableKeyedCollection.cs" />
    5258    <Compile Include="IObservableList.cs" />
  • trunk/sources/HeuristicLab.Collections/3.3/HeuristicLabCollectionsPlugin.cs

    r2572 r2618  
    2929  /// Plugin class for HeuristicLab.Collections plugin.
    3030  /// </summary>
    31   [ClassInfo(Name = "HeuristicLab.Collections-3.2")]
    32   [PluginFile(Filename = "HeuristicLab.Collections-3.3.dll", Filetype = PluginFileType.Assembly)]
    33   [Dependency(Dependency = "HeuristicLab.Persistence-3.3")]
     31  [Plugin("HeuristicLab.Collections-3.3")]
     32  [PluginFile("HeuristicLab.Collections-3.3.dll", PluginFileType.Assembly)]
     33  [PluginDependency("HeuristicLab.Persistence-3.3")]
    3434  public class HeuristicLabCollectionsPlugin : PluginBase {
    3535  }
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableCollection.cs

    r2575 r2618  
    2626
    2727namespace HeuristicLab.Collections {
    28   public interface IObservableCollection<T> : ICollection<T>, IDisposable {
     28  public interface IObservableCollection<T> : ICollection<T> {
    2929    event CollectionItemsChangedEventHandler<T> ItemsAdded;
    3030    event CollectionItemsChangedEventHandler<T> ItemsRemoved;
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableDictionary.cs

    r2574 r2618  
    2626
    2727namespace HeuristicLab.Collections {
    28   public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IObservableCollection<KeyValuePair<TKey, TValue>> {
     28  public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
     29    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded;
     30    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved;
    2931    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced;
     32    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset;
    3033  }
    3134}
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableKeyedCollection.cs

    r2575 r2618  
    2626
    2727namespace HeuristicLab.Collections {
    28   public interface IObservableKeyedCollection<TKey, TItem> : IObservableCollection<TItem> {
     28  public interface IObservableKeyedCollection<TKey, TItem> : ICollection<TItem> {
     29    TItem this[TKey key] { get; }
     30
     31    bool ContainsKey(TKey key);
     32    bool TryGetValue(TKey key, out TItem item);
     33
     34    event CollectionItemsChangedEventHandler<TItem> ItemsAdded;
     35    event CollectionItemsChangedEventHandler<TItem> ItemsRemoved;
    2936    event CollectionItemsChangedEventHandler<TItem> ItemsReplaced;
     37    event CollectionItemsChangedEventHandler<TItem> CollectionReset;
    3038  }
    3139}
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableList.cs

    r2574 r2618  
    2626
    2727namespace HeuristicLab.Collections {
    28   public interface IObservableList<T> : IList<T>, IObservableCollection<IndexedItem<T>> {
     28  public interface IObservableList<T> : IList<T> {
     29    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;
     30    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;
    2931    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced;
    3032    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved;
     33    event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;
    3134  }
    3235}
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs

    r2575 r2618  
    4242      get { return list.Count; }
    4343    }
    44     public bool IsReadOnly {
     44    bool ICollection<T>.IsReadOnly {
    4545      get { return ((ICollection<T>)list).IsReadOnly; }
    4646    }
     
    5757      list = new List<T>(collection);
    5858      OnItemsAdded(collection);
    59     }
    60     #endregion
    61 
    62     #region Destructors
    63     ~ObservableCollection() {
    64       Dispose(false);
    65     }
    66     protected virtual void Dispose(bool disposing) {
    67       if (disposing) {
    68         Clear();
    69       }
    70     }
    71     public void Dispose() {
    72       Dispose(true);
    73       GC.SuppressFinalize(this);
    7459    }
    7560    #endregion
     
    137122
    138123    #region Conversion
    139     public ReadOnlyCollection<T> AsReadOnly() {
    140       return list.AsReadOnly();
     124    public ReadOnlyObservableCollection<T> AsReadOnly() {
     125      return new ReadOnlyObservableCollection<T>(this);
    141126    }
    142127    public T[] ToArray() {
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs

    r2575 r2618  
    9191    #endregion
    9292
    93     #region Destructors
    94     ~ObservableDictionary() {
    95       Dispose(false);
    96     }
    97     protected virtual void Dispose(bool disposing) {
    98       if (disposing) {
    99         Clear();
    100       }
    101     }
    102     public void Dispose() {
    103       Dispose(true);
    104       GC.SuppressFinalize(this);
    105     }
    106     #endregion
    107 
    10893    #region Access
    10994    public bool ContainsKey(TKey key) {
     
    157142
    158143    #region Conversion
     144    public ReadOnlyObservableDictionary<TKey, TValue> AsReadOnly() {
     145      return new ReadOnlyObservableDictionary<TKey, TValue>(this);
     146    }
    159147    void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
    160148      ((ICollection<KeyValuePair<TKey, TValue>>)dict).CopyTo(array, arrayIndex);
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs

    r2575 r2618  
    4141      get { return dict.Comparer; }
    4242    }
    43     public bool IsReadOnly {
     43    bool ICollection<TItem>.IsReadOnly {
    4444      get { return ((ICollection<KeyValuePair<TKey, TItem>>)dict).IsReadOnly; }
    4545    }
     
    7878        dict.Add(GetKeyForItem(item), item);
    7979      OnItemsAdded(collection);
    80     }
    81     #endregion
    82 
    83     #region Destructors
    84     ~ObservableKeyedCollectionBase() {
    85       Dispose(false);
    86     }
    87     protected virtual void Dispose(bool disposing) {
    88       if (disposing) {
    89         Clear();
    90       }
    91     }
    92     public void Dispose() {
    93       Dispose(true);
    94       GC.SuppressFinalize(this);
    9580    }
    9681    #endregion
     
    115100
    116101    #region Access
    117     public bool Contains(TKey key) {
     102    public bool ContainsKey(TKey key) {
    118103      return dict.ContainsKey(key);
    119104    }
     
    203188
    204189    #region Conversion
     190    public ReadOnlyObservableKeyedCollection<TKey, TItem> AsReadOnly() {
     191      return new ReadOnlyObservableKeyedCollection<TKey, TItem>(this);
     192    }
    205193    public TItem[] ToArray() {
    206194      return dict.Values.ToArray();
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs

    r2575 r2618  
    4545      get { return ((ICollection<T>)list).IsReadOnly; }
    4646    }
    47     bool ICollection<IndexedItem<T>>.IsReadOnly {
    48       get { return ((ICollection<T>)list).IsReadOnly; }
    49     }
    5047
    5148    public T this[int index] {
     
    7471    #endregion
    7572
    76     #region Destructors
    77     ~ObservableList() {
    78       Dispose(false);
    79     }
    80     protected virtual void Dispose(bool disposing) {
    81       if (disposing) {
    82         Clear();
    83       }
    84     }
    85     public void Dispose() {
    86       Dispose(true);
    87       GC.SuppressFinalize(this);
    88     }
    89     #endregion
    90 
    9173    #region Access
    9274    public List<T> GetRange(int index, int count) {
     
    9678    public bool Contains(T item) {
    9779      return list.Contains(item);
    98     }
    99     public bool Contains(IndexedItem<T> item) {
    100       return list[item.Index].Equals(item.Value);
    10180    }
    10281
     
    170149      list.Add(item);
    171150      OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) });
    172     }
    173     public void Add(IndexedItem<T> item) {
    174       list.Insert(item.Index, item.Value);
    175       OnItemsAdded(new IndexedItem<T>[] { item });
    176151    }
    177152    public void AddRange(IEnumerable<T> collection) {
     
    209184      return false;
    210185    }
    211     public bool Remove(IndexedItem<T> item) {
    212       if (list[item.Index].Equals(item.Value)) {
    213         list.RemoveAt(item.Index);
    214         OnItemsRemoved(new IndexedItem<T>[] { item });
    215         return true;
    216       }
    217       return false;
    218     }
    219186    public int RemoveAll(Predicate<T> match) {
    220187      if (match == null) throw new ArgumentNullException();
     
    279246
    280247    #region Conversion
    281     public ReadOnlyCollection<T> AsReadOnly() {
    282       return list.AsReadOnly();
     248    public ReadOnlyObservableList<T> AsReadOnly() {
     249      return new ReadOnlyObservableList<T>(this);
    283250    }
    284251    public T[] ToArray() {
     
    287254    void ICollection<T>.CopyTo(T[] array, int arrayIndex) {
    288255      list.CopyTo(array, arrayIndex);
    289     }
    290     void ICollection<IndexedItem<T>>.CopyTo(IndexedItem<T>[] array, int arrayIndex) {
    291       IndexedItem<T>[] items = GetIndexedItems();
    292       items.CopyTo(array, arrayIndex);
    293256    }
    294257    public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter) {
     
    312275    IEnumerator<T> IEnumerable<T>.GetEnumerator() {
    313276      return ((IEnumerable<T>)list).GetEnumerator();
    314     }
    315     IEnumerator<IndexedItem<T>> IEnumerable<IndexedItem<T>>.GetEnumerator() {
    316       int index = -1;
    317       foreach (T item in list) {
    318         index++;
    319         yield return new IndexedItem<T>(index, item);
    320       }
    321277    }
    322278    IEnumerator IEnumerable.GetEnumerator() {
Note: See TracChangeset for help on using the changeset viewer.