public static CompositeDisposable TrackChangesDerrived <T>(this IReactiveList <T> list, IList <T> target,
                                                            Func <T, bool> filter = null)
 {
     if (list == null)
     {
         throw new ArgumentNullException(nameof(list));
     }
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     return(list.TrackChanges(target.Add, x => target.Remove(x),
                              reset => reset.SyncCollectionLocked(target), filter));
 }
 public static CompositeDisposable KeepCollectionInSync2 <T, T2>(this IReactiveList <T> list, IList <T2> destination,
                                                                 Func <T, bool> filter = null) where T : T2
 {
     if (list == null)
     {
         throw new ArgumentNullException(nameof(list));
     }
     if (destination == null)
     {
         throw new ArgumentNullException(nameof(destination));
     }
     lock (list) {
         list.SyncCollection2Locked(destination, filter);
         return(list.TrackChanges(x => destination.Add(x), x => destination.Remove(x),
                                  reset => reset.SyncCollection2Locked(destination), filter));
     }
 }
 public static CompositeDisposable TrackChangesDerrivedConvert <T, T2>(this IReactiveList <T> list,
                                                                       IList <T2> target,
                                                                       Func <T, T2> convert, Func <T, bool> filter = null) where T2 : class
 {
     if (list == null)
     {
         throw new ArgumentNullException(nameof(list));
     }
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     return(list.TrackChanges(x => target.AddWhenMissing(convert(x)), x => target.Remove(convert(x)), l => {
         target.Clear();
         target.AddRange(l.Select(convert));
     }, filter));
 }
示例#4
0
 void SetupCollectionItems <T>(IReactiveList <T> src, IReactiveList <IHierarchicalLibraryItem> dst,
                               Func <T, bool> predicate = null) where T : Collection
 {
     lock (src) {
         var srcF = predicate == null ? src : src.Where(predicate);
         lock (dst)
             dst.AddRange(srcF.Select(CreateCustomModSet));
         _disposables.Add(src.TrackChanges(
                              x => dst.AddLocked(CreateCustomModSet(x)),
                              x => {
             lock (CollectionsGroup.Children)
                 dst.RemoveLocked(GetCollection(x));
         },
                              reset => {
             lock (dst) {
                 lock (CollectionsGroup.Children)
                     dst.RemoveAll(GetCollections().ToArray());
                 dst.AddRange(reset.Select(CreateCustomModSet));
             }
         }, predicate));
     }
 }