Skip to main content

ForwardedList<T>

A class in Root.Township, Alta.Utilities.

A read-only view onto another listened list that can be swapped at runtime. It forwards the target's add, remove and target-changed events as its own, and reads as empty with no target.

Constructors​

MemberWhat it is
ForwardedList()Creates a ForwardedList with default values.

Fields​

2 private and internal fields
MemberWhat it is
private List<T> emptyEmpty list returned when there is no target.
private IListenedList<T> targetBacking field for Target.

Properties​

MemberWhat it is
int Count { get; }Item count of the current target, or 0 with none.
T this[int index] { get; }Item at the index in the current target.
IListenedList<T> Target { get; }The list currently forwarded.
protected List<T> Internal { get; }The target's backing list, or an empty list when there is no target.

Events​

MemberWhat it is
event ListItemChangedHandler<T> ItemAddedRaised when an item is added to the current target.
event ListItemChangedHandler<T> ItemRemovedRaised when an item is removed from the current target.
event TargetChangedHandler<T> TargetChangedRaised with the old and new target when the target changes, including in nested forwarded lists.

Methods​

MemberWhat it is
bool Contains(T item)Whether the current target contains the item.
IEnumerator<T> GetEnumerator()Enumerates the current target's items.
void SetTarget(IListenedList<T> newTarget)Switches to a new target list, moving event hooks and raising TargetChanged. Items are not re-announced.
4 private and internal methods
MemberWhat it is
private void Add(IListenedList<T> list, T item)Forwards the target's ItemAdded as this list's ItemAdded.
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Enumerates the current target's items.
private void ParentTargetChanged(ForwardedList<T> list, IListenedList<T> oldTarget, IListenedList<T> newTarget)Passes on a target change from a nested forwarded list.
private void Remove(IListenedList<T> list, T item)Forwards the target's ItemRemoved as this list's ItemRemoved.

Used in​

Members of other types that take, return or hold a ForwardedList&lt;T>: