/// <summary> /// Constructs a observable read only list, which concatenates two observable readonly lists. /// </summary> /// <param name="firstCollection"></param> /// <param name="secondCollection"></param> /// <param name="notificationScheduler">On this scheduler the notifications are emitted.</param> public ConcatenatingObservableReadOnlyList(IObservableReadOnlyList <T> firstCollection, IObservableReadOnlyList <T> secondCollection, IScheduler notificationScheduler) { _firstBackingList = firstCollection; _secondBackingList = secondCollection; ConnectToCollectionChangedOnScheduler(firstCollection, secondCollection, notificationScheduler); }
/// <summary> /// Constructs a observable read only list, which concatenates two observable readonly lists. /// </summary> /// <param name="firstCollection"></param> /// <param name="secondCollection"></param> public ConcatenatingObservableReadOnlyList(IObservableReadOnlyList <T> firstCollection, IObservableReadOnlyList <T> secondCollection) { _firstBackingList = firstCollection; _secondBackingList = secondCollection; ConnectToCollectionChanged(firstCollection, secondCollection); }
/// <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> /// 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)); }
private static void UninitializedCheck( IObservableReadOnlyList <A> readOnlyList) { if (readOnlyList == null) { throw new ArgumentNullException(nameof(readOnlyList)); } Assert.Equal(0, readOnlyList.Count); }
/// <summary> /// Constructs a TransformingObservableReadOnlyList synchronizing with an IObservableReadOnlyList source. /// Intended to be used only by the constructors. /// </summary> /// <param name="source">List to synchronize with.</param> /// <param name="transform">Logic to transform a TSource object to a TResult object.</param> public TransformingObservableReadOnlyList(IObservableReadOnlyList <TSource> source, Func <TSource, TResult> transform) { //The source collection may already have items. Thus, they are transformed and added to the backing list. foreach (TSource from in source) { _backingList.Add(transform(from)); } ConnectToCollectionChanged(source, transform); }
private static void StandardCheck(ObservableCollection <A> filledCollection, IObservableReadOnlyList <A> readOnlyList) { Assert.Equal(filledCollection.Count, readOnlyList.Count); int index = 0; foreach (A a in readOnlyList) { Assert.Same(a, filledCollection[index++]); } }
public static ReadOnlyObservableCollection <T> ToReadOnlyObservableCollection <T>( this IObservableReadOnlyList <T> list) { var observableCollection = new ObservableCollection <T>(list); list.CollectionChanged += (sender, args) => { switch (args.Action) { case NotifyCollectionChangedAction.Add: int i = args.NewStartingIndex; foreach (T item in args.NewItems.Cast <T>()) { observableCollection.Insert(i++, item); } break; case NotifyCollectionChangedAction.Remove: for (int l = 0; l < args.OldItems.Count; l++) { observableCollection.RemoveAt(args.OldStartingIndex); } break; case NotifyCollectionChangedAction.Replace: for (int l = 0; l < args.OldItems.Count; l++) { observableCollection.RemoveAt(args.OldStartingIndex); } int j = args.NewStartingIndex; foreach (T item in args.NewItems.Cast <T>()) { observableCollection.Insert(j++, item); } break; case NotifyCollectionChangedAction.Move: IList movedItems = new List <T>(); for (int l = 0; l < args.OldItems.Count; l++) { T movedItem = observableCollection[args.OldStartingIndex]; movedItems.Add(movedItem); observableCollection.RemoveAt(args.OldStartingIndex); } int k = args.NewStartingIndex; foreach (T movedItem in movedItems) { observableCollection.Insert(k++, movedItem); } break; case NotifyCollectionChangedAction.Reset: observableCollection.Clear(); break; default: throw new Exception("Something unexpected happened with the source collection."); } }; return(new ReadOnlyObservableCollection <T>(observableCollection)); }
public static IObservableReadOnlyList <T> Concatenate <T>( this IObservableReadOnlyList <T> first, ReadOnlyObservableCollection <T> second, IScheduler notificationScheduler) => new ConcatenatingObservableReadOnlyList <T>(first, second.ToObservableReadOnlyList(), notificationScheduler);
public static IObservableReadOnlyList <TResult> Transform <TSource, TResult>( this IObservableReadOnlyList <TSource> source, Func <TSource, TResult> transform, IScheduler notificationScheduler) => new TransformingObservableReadOnlyList <TSource, TResult>(source, transform, notificationScheduler);
public static IObservableReadOnlyList <T> Concatenate <T>( this IObservableReadOnlyList <T> first, ReadOnlyObservableCollection <T> second) => new ConcatenatingObservableReadOnlyList <T>(first, second.ToObservableReadOnlyList());
public static IObservableReadOnlyList <T> Concatenate <T>( this IObservableReadOnlyList <T> first, IObservableReadOnlyList <T> second) => new ConcatenatingObservableReadOnlyList <T>(first, second);
public static IObservableReadOnlyList <TResult> Transform <TSource, TResult>( this IObservableReadOnlyList <TSource> source, Func <TSource, TResult> transform) => new TransformingObservableReadOnlyList <TSource, TResult>(source, transform);
public static IObservable <IChange <IListOperation <T> > > AsObservable <T>( [NotNull] this IObservableReadOnlyList <T> list) => list.WhenUpdated.StartWith(new ListInsertBatchOperation <T>(list, 0)).NotNull();
/// <summary> /// For the sake of completeness. Directly delegates construction to the constructor. /// </summary> /// <param name="collectionA">First concatenated collection.</param> /// <param name="collectionB">Second concatenated collection.</param> /// <returns>A concatenating read only list, which takes two observable read only list.</returns> public static ConcatenatingObservableReadOnlyList <T> Concatenate(IObservableReadOnlyList <T> collectionA, IObservableReadOnlyList <T> collectionB) { return(new ConcatenatingObservableReadOnlyList <T>(collectionA, collectionB)); }