mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-25 15:58:09 +03:00
67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
namespace ServiceLib.Base;
|
|
|
|
public class BulkObservableCollection<T> : ObservableCollection<T>
|
|
{
|
|
private bool _suppressNotification = false;
|
|
|
|
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
|
{
|
|
if (!_suppressNotification)
|
|
{
|
|
base.OnCollectionChanged(e);
|
|
}
|
|
}
|
|
|
|
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
|
|
{
|
|
if (!_suppressNotification)
|
|
{
|
|
base.OnPropertyChanged(e);
|
|
}
|
|
}
|
|
|
|
public void AddRange(IEnumerable<T>? collection)
|
|
{
|
|
if (collection == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_suppressNotification = true;
|
|
try
|
|
{
|
|
foreach (var item in collection)
|
|
{
|
|
Add(item);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_suppressNotification = false;
|
|
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Count)));
|
|
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
}
|
|
}
|
|
|
|
public bool Replace(T oldItem, T newItem)
|
|
{
|
|
var index = Items.IndexOf(oldItem);
|
|
if (index < 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Items[index] = newItem;
|
|
|
|
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
|
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(
|
|
NotifyCollectionChangedAction.Replace,
|
|
newItem,
|
|
oldItem,
|
|
index));
|
|
|
|
return true;
|
|
}
|
|
}
|