Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ public ObservableCollection(IEnumerable<T> collection)
CopyFrom(collection);
}

private void CopyFrom(IEnumerable<T> collection)
{
IList<T> items = Items;
if (collection != null && items != null)
{
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
items.Add(enumerator.Current);
}
}
}
}

#endregion Constructors


Expand All @@ -84,6 +69,29 @@ public void Move(int oldIndex, int newIndex)
{
MoveItem(oldIndex, newIndex);
}

/// <summary>
/// Adds a range of objects but does not raise the OnCollectionChanged event until all objects are added.
/// </summary>
/// <param name="collection">The set of objects to be added.</param>
/// <param name="clearFirst">Determines whether or not to remove any existing items in the collection first. Defaults to False.</param>
public void AddRange(IEnumerable<T> collection, bool clearFirst = false)
{
CheckReentrancy();

if (clearFirst) Items.Clear();

var newIndex = Items.Count;
foreach (var item in collection)
{
base.InsertItem(newIndex, item);
newIndex++;
}

OnPropertyChanged(CountString);
OnPropertyChanged(IndexerName);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new List<T>(collection)));
}

#endregion Public Methods

Expand Down Expand Up @@ -292,6 +300,24 @@ protected void CheckReentrancy()
//------------------------------------------------------

#region Private Methods
/// <summary>
/// Copies an existing collection into this one.
/// </summary>
private void CopyFrom(IEnumerable<T> collection)
{
IList<T> items = Items;
if (collection != null && items != null)
{
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
items.Add(enumerator.Current);
}
}
}
}

/// <summary>
/// Helper to raise a PropertyChanged event />).
/// </summary>
Expand Down