|
Enhanced C#
Loyc library documentation
|
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...
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.
| T | Type of items in the list |
| TCollection | Type 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.
Events | |
| ListChangingHandler< T, TCollection > | ListChanging |
| Occurs when the collection associated with this interface is about to change. More... | |
| ListChangingHandler<T, TCollection> Loyc.Collections.INotifyListChanging< T, TCollection >.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. When throwing an exception, be aware that this can cause other event handlers attached to the same event not to receive any change notification.
1.8.7