public void AddRange(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var oldRaiseEventsValue = RaiseListChangedEvents; var start = this.Items.Count; var ammount = collection.Count(); try { RaiseListChangedEvents = false; foreach (var value in collection) { Add(value); } } finally { RaiseListChangedEvents = oldRaiseEventsValue; ListRangeChanged?.Invoke(this, new RangeChangdEventArgs(start, ammount, RangeChangeType.Add)); } }
public void RemoveRange(int start, int ammount) { if (start + ammount > Items.Count) { throw new IndexOutOfRangeException(); } var oldRaiseEventsValue = RaiseListChangedEvents; var items = new List <T>(); try { RaiseListChangedEvents = false; for (int index = start; index < start + ammount; index++) { items.Add(Items[index]); base.RemoveItem(index); } BeforeRemoveRange?.Invoke(this, items); } finally { RaiseListChangedEvents = oldRaiseEventsValue; ListRangeChanged?.Invoke(this, new RangeChangdEventArgs(start, ammount, RangeChangeType.Remove)); } }