Enhanced C#
Language of your choice: library documentation
Loyc.Collections.INotifyListChanging< T, TCollection > Interface Template Reference

Encapsulates the ListChanging event that notifies listeners of dynamic changes to a collection, such as when items are about to be added and removed or the whole list is about to be refreshed. More...


Source file:

Remarks

Encapsulates the ListChanging event that notifies listeners of dynamic changes to a collection, such as when items are about to be added and removed or the whole list is about to be refreshed.

Template Parameters
TType of items in the list
TCollectionType of the first argument of the event

This approach to change notification is more lightweight than the standard INotifyCollectionChanged interface because that interface sends both a list of new items and a list of old items, so many changes require a pair of temporary objects to be created that hold the two lists of items.

In contrast, the ListChanging event includes only one list that specifies the set of new items. In the case of Remove events, no change list is included. Since the collection has not been modified yet, the user handling the event can examine the list to learn which item(s) are being removed; if the list is being changed, it can similarly examine the list to see the old set of items.

An optimization is available when only a single item is being added or changed. In that case, the collection class should create a lightweight read-only single-item list by calling ListExt.Single<T>(T). Such a list has less overhead than List<T> and the same overhead as an array of one item.