2021-01-12 13:41:50 +11:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Core.Collections
|
2021-01-12 13:41:50 +11:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Allows clearing all event handlers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TValue"></typeparam>
|
2021-01-12 15:38:18 +11:00
|
|
|
|
public class EventClearingObservableCollection<TValue> : ObservableCollection<TValue>, INotifyCollectionChanged
|
2021-01-12 13:41:50 +11:00
|
|
|
|
{
|
|
|
|
|
|
public EventClearingObservableCollection()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public EventClearingObservableCollection(List<TValue> list) : base(list)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public EventClearingObservableCollection(IEnumerable<TValue> collection) : base(collection)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-12 15:38:18 +11:00
|
|
|
|
// need to explicitly implement with event accessor syntax in order to override in order to to clear
|
|
|
|
|
|
// c# events are weird, they do not behave the same way as other c# things that are 'virtual',
|
|
|
|
|
|
// a good article is here: https://medium.com/@unicorn_dev/virtual-events-in-c-something-went-wrong-c6f6f5fbe252
|
|
|
|
|
|
// and https://stackoverflow.com/questions/2268065/c-sharp-language-design-explicit-interface-implementation-of-an-event
|
|
|
|
|
|
private NotifyCollectionChangedEventHandler _changed;
|
|
|
|
|
|
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
|
|
|
|
|
|
{
|
|
|
|
|
|
add { _changed += value; }
|
|
|
|
|
|
remove { _changed -= value; }
|
|
|
|
|
|
}
|
2021-01-12 13:41:50 +11:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clears all event handlers for the <see cref="CollectionChanged"/> event
|
|
|
|
|
|
/// </summary>
|
2021-01-12 15:38:18 +11:00
|
|
|
|
public void ClearCollectionChangedEvents() => _changed = null;
|
2021-01-12 13:41:50 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|