/// <summary> /// Constructs a concatenating read only list, which takes a ObservableCollection (first) and another observable read only list (second). /// </summary> /// <typeparam name="TA">Item type of the first collection. Should inherit from T.</typeparam> /// <param name="collectionA">First concatenated collection.</param> /// <param name="collectionB">Second concatenated collection.</param> /// <returns>A concatenating read only list, which takes a ObservableCollection and another observable read only list.</returns> public static ConcatenatingObservableReadOnlyList <T> Concatenate <TA>(ObservableCollection <TA> collectionA, IObservableReadOnlyList <T> collectionB) where TA : class, T { IObservableReadOnlyList <T> wrapA = new WrappingObservableReadOnlyList <TA>(collectionA); return(new ConcatenatingObservableReadOnlyList <T>(wrapA, collectionB)); }
/// <summary> /// Constructs a concatenating read only list, which takes a ObservableCollection (second) and another observable read only list (first). /// </summary> /// <typeparam name="TB">Item type of the second collection. Should inherit from T.</typeparam> /// <param name="collectionA">First concatenated collection.</param> /// <param name="collectionB">Second concatenated collection.</param> /// <returns>A concatenating read only list, which takes a ObservableCollection and another observable read only list.</returns> public static ConcatenatingObservableReadOnlyList <T> Concatenate <TB>(IObservableReadOnlyList <T> collectionA, ObservableCollection <TB> collectionB) where TB : class, T { IObservableReadOnlyList <T> wrapB = new WrappingObservableReadOnlyList <TB>(collectionB); return(new ConcatenatingObservableReadOnlyList <T>(collectionA, wrapB)); }
/// <summary> /// The enumeration which the task fetches is transformed to an IObservableReadOnlyList. /// The IObservableReadOnlyList however is returned immediately and fills itself as soon as the task is completed. /// The IObservableReadOnlyList has no further connection to the fetched enumeration. So if it is a list and gets additions afterward the IObservableReadOnlyList will not notice it. /// </summary> /// <typeparam name="TItem">Item type.</typeparam> /// <typeparam name="TEnumerable">Item type.</typeparam> /// <param name="task">Task which fetches the observable collection.</param> /// <returns></returns> public static IObservableReadOnlyList <TItem> ToObservableReadOnlyList <TEnumerable, TItem>( this Task <TEnumerable> task) where TEnumerable : IEnumerable <TItem> { var source = new ObservableCollection <TItem>(); var returnedCollection = new WrappingObservableReadOnlyList <TItem>(source); task.ContinueWith(async t => { if (t.IsFaulted) { throw t.Exception; } foreach (var item in await t.ConfigureAwait(false)) { source.Add(item); } }); return(returnedCollection); }