This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
using DTS.Common.Utilities.Logging;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
namespace DTS.Common.Classes
{
/// <summary>
/// this is a helper class to avoid performance issues
/// adding or removing a bulk sequence of items from the collection
/// by firing just one notification rather than n
/// </summary>
/// <typeparam name="T"></typeparam>
public class BulkObservableCollection<T> : ObservableCollection<T>
{
public void AddRange(IEnumerable<T> items)
{
try
{
// Turn off notifications (check if anyone is listening first)
CheckReentrancy();
foreach (var item in items) { Items.Add(item); }
// Fire a single notification that the entire "Reset" happened
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Count)));
}
catch( Exception ex)
{
APILogger.Log(ex);
}
}
public void RemoveRange(IEnumerable<T> itemsToRemove)
{
try
{
CheckReentrancy();
foreach (var item in itemsToRemove)
{
Items.Remove(item);
}
// Fire one single notification for the entire operation
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Count)));
}
catch( Exception ex)
{
APILogger.Log(ex);
}
}
}
}