Skip to content

IObservableReadOnlyList

Yeah69 edited this page Nov 3, 2016 · 2 revisions

Intention

Make read-only lists observable.

Motivation

Now, you might think: Why should I make a list with read-only access observable? Why should I wait for it to change? The short answer is that these lists are proxies to other obsevable lists. These other lists can be observable read-only lists, too, or ObservableCollections. What purpose the concrete implementations of this interface have, you can look up on their wiki pages.

Features

The interface is a composition of the IReadOnlyList, INotifyCollectionChanged and INotifyPropertyChanged interfaces. All of which are supported by WPF elements, so it has the same effect like an ObservableCollection on the WPF UI. Note that the typ T is marked as out, which allows it to be used in co-variant way:

Example

IObservableReadOnlyList<DerivedClass> derivedItemsList = new WrappingObservableReadOnlyList<DerivedClass>(new ObservableCollection<DerivedClass>());
IObservableReadOnlyList<BaseClass> baseItemsList = derivedItemsList; //legit, because DerivedClass inherits from BaseClass and the interfaces type is co-variant

The co-variance feature is a requirement for the ConcatenatingObservableReadOnlyList (see it's wiki page).

Clone this wiki locally