/// <summary> /// Adds the elements of the specified collection to the end of the <see cref="ObservableSortedCollection{T}"/>. /// </summary> /// <param name="collection">The collection whose elements should be added to the end of the <see cref="ObservableSortedCollection{T}"/>. /// The collection itself cannot be null, but it can contain elements that are null, if type <typeparamref name="T"/> is a reference type.</param> /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception> public void AddRange(IEnumerable<T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } // The items to be added in sorted order var changedItems = new SortedArray<T>(this.Comparer); changedItems.AddAll(collection); if (changedItems.Count != 0) { // Since changedItems are already sorted, use AddSorted instead of AddAll this.items.AddSorted(changedItems); var startingIndex = this.IndexOf(changedItems[0]); this.OnPropertyChanged(nameof(this.Count)); this.OnPropertyChanged(IndexerName); this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new List<T>(changedItems), startingIndex)); } }