Ignore:
Timestamp:
02/08/16 14:24:18 (4 years ago)
Author:
abeham
Message:

#2575: fixed multiple enumeration of collection in ObservableCollection and ObservableList

Location:
trunk/sources/HeuristicLab.Collections/3.3
Files:
2 edited

Legend:

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

    r12012 r13597  
    2020#endregion
    2121
     22using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2223using System;
    2324using System.Collections;
    2425using System.Collections.Generic;
    2526using System.ComponentModel;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System.Linq;
    2728
    2829namespace HeuristicLab.Collections {
     
    9697    public void AddRange(IEnumerable<T> collection) {
    9798      int capacity = list.Capacity;
    98       int count = list.Count;
    99       list.AddRange(collection);
    100       if (list.Count != count) {
     99      ICollection<T> items = collection as ICollection<T> ?? collection.ToList();
     100      list.AddRange(items);
     101      if (items.Count > 0) {
    101102        if (list.Capacity != capacity)
    102103          OnPropertyChanged("Capacity");
    103104        OnPropertyChanged("Count");
    104         OnItemsAdded(collection);
     105        OnItemsAdded(items);
    105106      }
    106107    }
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs

    r12012 r13597  
    2020#endregion
    2121
     22using HeuristicLab.Common;
     23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2224using System;
    2325using System.Collections;
     
    2527using System.ComponentModel;
    2628using System.Linq;
    27 using HeuristicLab.Common;
    28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    3030namespace HeuristicLab.Collections {
     
    169169      int capacity = list.Capacity;
    170170      int index = list.Count;
    171       list.AddRange(collection);
    172171      List<IndexedItem<T>> items = new List<IndexedItem<T>>();
    173172      foreach (T item in collection) {
     
    175174        index++;
    176175      }
     176      list.AddRange(items.Select(x => x.Value));
    177177      if (items.Count > 0) {
    178178        OnItemsAdded(items);
    179         OnItemsAdded(collection);
     179        OnItemsAdded(items.Select(x => x.Value));
    180180        if (list.Capacity != capacity)
    181181          OnPropertyChanged("Capacity");
Note: See TracChangeset for help on using the changeset viewer.