Example #1
0
        public static void DisposeItemsAndClear <T>(this BindingList <T> list) where T : IDisposable
        {
            foreach (var t in list)
            {
                t.Dispose();
            }

            list.DisposeItemsAndClear();
        }
Example #2
0
        public static IDisposable Filter(this BindingList <Item> source, BindingList <Item> result, IObservable <Func <Item, bool> > filter, IScheduler observer)
        {
            // firstly selecting default values for source list and filter observable for getting result
            var combinedList   = Observable.Return(Unit.Default).Merge(source.RaiseListChangedEvents.WhenAnyValue(_ => Unit.Default)).Select(_ => source);
            var combinedFilter = Observable.Return(new Func <Item, bool>(t => true)).Merge(filter);

            var d0 = combinedList.CombineLatest(combinedFilter, (l, f) => l.Select(x => x.Filter(f)).Where(x => x != null))
                     .ObserveOn(observer)
                     .Subscribe(x =>
            {
                //
                //using (result.SuppressChangeNotifications())
                //{
                //
                //}
                result.DisposeItemsAndClear();
                result.AddRange(x);
            });

            return(new CompositeDisposable(d0));
        }