Enhanced C#
Language of your choice: library documentation
Events | List of all members
Loyc.Collections.INotifyListChanging< T > Interface Template Reference

Encapsulates the ListChanging event that notifies listeners of dynamic changes to an indexed list, such as when items get added and removed or the whole list is refreshed. More...


Source file:
Inheritance diagram for Loyc.Collections.INotifyListChanging< T >:
Loyc.Collections.AListBase< K, T > Loyc.Collections.AListBase< K, T >

Remarks

Encapsulates the ListChanging event that notifies listeners of dynamic changes to an indexed list, such as when items get added and removed or the whole list is refreshed.

Template Parameters
TType of items in the list

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.

Events

ListChangingHandler< T > ListChanging
 Occurs when the collection associated with this interface is about to change. More...
 

Event Documentation

ListChangingHandler<T> Loyc.Collections.INotifyListChanging< T >.ListChanging

Occurs when the collection associated with this interface is about to change.

The event handler receives a ListChangeInfo<T> argument, which describes the change.

The event handler is not allowed to modify the list that is changing while it is handling the event, but it can read the list.

IMPORTANT: if the event handler throws an exception, the change does not actually happen. Collections that support this event must ensure that the collection is not left in an invalid state in the event that a ListChanging event handler throws an exception.