wasSharp
/Collections/Specialized/ExtendedObservableCollection.cs |
@@ -0,0 +1,43 @@ |
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
// rights of fair usage, the disclaimer and warranty conditions. // |
/////////////////////////////////////////////////////////////////////////// |
|
using System; |
using System.Collections.Generic; |
using System.Collections.ObjectModel; |
using System.Collections.Specialized; |
|
namespace wasSharp.Collections.Specialized |
{ |
/// <summary> |
/// An observable collection allowing the add of a range of items. |
/// </summary> |
/// <typeparam name="T">the collection type</typeparam> |
public class ExtendedObservableCollection<T> : ObservableCollection<T> |
{ |
private bool _suppressNotification; |
|
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) |
{ |
if (!_suppressNotification) |
base.OnCollectionChanged(e); |
} |
|
public void AddRange(IEnumerable<T> list) |
{ |
if (list == null) |
throw new ArgumentNullException(nameof(list)); |
|
_suppressNotification = true; |
|
foreach (var item in list) |
{ |
Add(item); |
} |
_suppressNotification = false; |
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); |
} |
} |
} |