Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.