Пример #1
0
        public GroupingViewAdapter(
            InputCollectionWrapper <TSource> source,
            LinqContinuousCollection <GroupedContinuousCollection <TKey, TElement> > output,
            Expression <Func <TSource, TKey> > keySelector,
            Expression <Func <TSource, TElement> > elementSelector,
            IEqualityComparer <TKey> comparer)
            : base(source, output,
                   ExpressionPropertyAnalyzer.GetReferencedPropertyNames(keySelector)[typeof(TSource)])
        {
            /*
             *     : base(source, output,
             * ExpressionPropertyAnalyzer.GetReferencedPropertyNames(keySelector)[typeof(TSource)].
             * */


            if (elementSelector == null)
            {
                throw new ArgumentNullException("elementSelector");
            }
            _keySelector     = keySelector.Compile();
            _elementSelector = elementSelector.Compile();
            if (comparer == null)
            {
                comparer = EqualityComparer <TKey> .Default;
            }
            _comparer = comparer;

            foreach (TSource item in this.InputCollection)
            {
                AddItem(item, -1);
            }
        }
Пример #2
0
        protected ViewAdapter(InputCollectionWrapper <Tin> input,
                              LinqContinuousCollection <Tout> output)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            _input  = input;
            _output = new OutputCollectionWrapper <Tout>(output);

            output.SourceAdapter = this;
            // Must be referenced by this instance:
            _collectionChangedDelegate = delegate(object sender, NotifyCollectionChangedEventArgs args)
            {
                OnInputCollectionChanged(args);
            };
            _propertyChangedDelegate = delegate(object sender, PropertyChangedEventArgs args)
            {
                OnCollectionItemPropertyChanged((Tin)sender, args.PropertyName);
            };
            new WeakCollectionChangedHandler(input.InnerAsNotifier, _collectionChangedDelegate);

            foreach (Tin item in this.InputCollection)
            {
                SubscribeToItem(item);
            }
        }
Пример #3
0
        protected SmartViewAdapter(InputCollectionWrapper <TInput> input,
                                   LinqContinuousCollection <TOutput> output,
                                   HashSet <string> monitoredProperties)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            _input  = input;
            _output = new OutputCollectionWrapper <TOutput>(output);
            _monitoredProperties = monitoredProperties;

            output.SourceAdapter = this;
            // Must be referenced by this instance:

            foreach (TInput item in _input.InnerAsList)
            {
                SubscribeToItem(item);
            }

            CollectionChangedEventManager.AddListener(
                _input.InnerAsNotifier, this);
        }
Пример #4
0
        private static ReadOnlyContinuousCollection <T> Where <T>(
            InputCollectionWrapper <T> source, Expression <Func <T, bool> > filterExpr) where T : INotifyPropertyChanged
        {
            LinqContinuousCollection <T> output = new LinqContinuousCollection <T>();

            new SmartFilterAdapter <T>(source, output, filterExpr);
            return(output);
        }
Пример #5
0
 public DistinctViewAdapter(InputCollectionWrapper <TSource> source,
                            LinqContinuousCollection <TSource> output,
                            IEqualityComparer <TSource> comparer)
     : base(source, output)
 {
     _comparer = comparer;
     ReEvaluate();
 }
Пример #6
0
        private static ReadOnlyContinuousCollection <TSource> Except <TSource>(
            InputCollectionWrapper <TSource> input1,
            InputCollectionWrapper <TSource> input2)
        {
            var output = new LinqContinuousCollection <TSource>();

            new ExceptViewAdapter <TSource>(input1, input2, output);
            return(output);
        }
Пример #7
0
        private static ReadOnlyContinuousCollection <TResult> SelectMany <TSource, TResult>(
            InputCollectionWrapper <TSource> source, Func <TSource, IEnumerable <TResult> > selector)
            where TSource :  INotifyPropertyChanged
        {
            LinqContinuousCollection <TResult> output = new LinqContinuousCollection <TResult>();

            new SelectingManyViewAdapter <TSource, TResult>(source, output, selector);

            return(output);
        }
Пример #8
0
        /// <summary>
        /// Private static method for Distinct operating using the
        /// default IEqualityComparer of T.
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        private static ReadOnlyContinuousCollection <TSource> Distinct <TSource>(
            InputCollectionWrapper <TSource> source)
            where TSource : INotifyPropertyChanged
        {
            LinqContinuousCollection <TSource> output = new LinqContinuousCollection <TSource>();

            new DistinctViewAdapter <TSource>(source, output);

            return(output);
        }
Пример #9
0
        private static ReadOnlyContinuousCollection <TSource> OrderByDescending <TSource, TKey>(
            InputCollectionWrapper <TSource> source, Expression <Func <TSource, TKey> > keySelector)
            where TSource :  INotifyPropertyChanged
            where TKey : IComparable
        {
            LinqContinuousCollection <TSource> output = new LinqContinuousCollection <TSource>();

            new SortingViewAdapter <TSource, TKey>(
                source, output,
                keySelector, true);
            return(output);
        }
Пример #10
0
        public FilteringViewAdapter(InputCollectionWrapper <T> input,
                                    LinqContinuousCollection <T> output,
                                    Func <T, bool> predicateFunc) : base(input, output)
        {
            _predicate = predicateFunc;

            foreach (T item in this.InputCollection)
            {
                if (_predicate(item))
                {
                    this.OutputCollection.Add(item);
                }
            }
        }
Пример #11
0
        private static ReadOnlyContinuousCollection <GroupedContinuousCollection <TKey, TElement> > GroupBy <TSource, TKey, TElement>(
            InputCollectionWrapper <TSource> source,
            Expression <Func <TSource, TKey> > keySelector,
            Expression <Func <TSource, TElement> > elementSelector,
            IEqualityComparer <TKey> comparer)
            where TSource :  INotifyPropertyChanged
            where TKey : IComparable
        {
            LinqContinuousCollection <GroupedContinuousCollection <TKey, TElement> > output =
                new LinqContinuousCollection <GroupedContinuousCollection <TKey, TElement> >();

            new GroupingViewAdapter <TSource, TKey, TElement>(source, output, keySelector, elementSelector, comparer);
            return(output);
        }
Пример #12
0
        public SortingViewAdapter(InputCollectionWrapper <TSource> input,
                                  LinqContinuousCollection <TSource> output, Expression <Func <TSource, TKey> > keySelectorExpr,
                                  bool descending)
            : base(input, output,
                   ExpressionPropertyAnalyzer.GetReferencedPropertyNames(keySelectorExpr)[typeof(TSource)])
        {
            if (keySelectorExpr == null)
            {
                throw new ArgumentNullException("keySelectorExpr");
            }
            _compareFunc = new FuncComparer <TSource, TKey>(keySelectorExpr.Compile(), descending);


            SetComparerChain(_compareFunc);
            FullSort(); // Because we do not know yet if we are last in chain.
        }
Пример #13
0
        public SelectingViewAdapter(InputCollectionWrapper <TSource> input,
                                    LinqContinuousCollection <TResult> output,
                                    Func <TSource, TResult> func)
            : base(input, output)
        {
            _func = func;

            if (func == null)
            {
                throw new ArgumentNullException("func");
            }
            foreach (TSource item in this.InputCollection)
            {
                this.OutputCollection.Add(func(item));
            }
        }
Пример #14
0
        public SelectingManyViewAdapter(InputCollectionWrapper <TSource> input,
                                        LinqContinuousCollection <TResult> output,
                                        Func <TSource, IEnumerable <TResult> > func)
            : base(input, output)
        {
            _func = func;

            if (func == null)
            {
                throw new ArgumentNullException("func");
            }
            foreach (TSource inItem in this.InputCollection)
            {
                List <TResult> outList = new List <TResult>(func(inItem));
                this.OutputCollection.AddRange(outList);
                _collectionLengths.Add(outList.Count);
            }
        }
Пример #15
0
        public SmartFilterAdapter(
            InputCollectionWrapper <T> input,
            LinqContinuousCollection <T> output,
            Expression <Func <T, bool> > predicateExpr) :
            base(input,
                 output,
                 ExpressionPropertyAnalyzer.GetReferencedPropertyNames(predicateExpr)[typeof(T)])
        {
            _predicate = predicateExpr.Compile();

            foreach (T item in input.InnerAsList)
            {
                if (_predicate(item))
                {
                    OutputCollection.Add(item);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// When a change occurs, which is not a property change on a collection item,
        /// but changes the result of a Where() filter
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source"></param>
        public static void ReEvaluate <TSource>(this ReadOnlyContinuousCollection <TSource> source)
        {
            LinqContinuousCollection <TSource> collection = source as LinqContinuousCollection <TSource>;

            if (collection == null)
            {
                return;
            }
            List <IViewAdapter> adapterCollection = new List <IViewAdapter>();
            IViewAdapter        adapter           = collection.SourceAdapter;

            while (adapter != null)
            {
                adapterCollection.Add(adapter);
                adapter = adapter.PreviousAdapter;
            }
            adapterCollection.Reverse();
            adapterCollection.ForEach(a => a.ReEvaluate());
        }
Пример #17
0
 public DistinctViewAdapter(InputCollectionWrapper <TSource> source,
                            LinqContinuousCollection <TSource> output) : base(source, output)
 {
     ReEvaluate();
 }
Пример #18
0
        public ExceptViewAdapter(InputCollectionWrapper <T> input1, InputCollectionWrapper <T> input2, LinqContinuousCollection <T> output)
        {
            if (input1 == null)
            {
                throw new ArgumentNullException("input1");
            }
            if (input2 == null)
            {
                throw new ArgumentNullException("input2");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            this.Input1 = input1;
            this.Input2 = input2;
            this.Output = new OutputCollectionWrapper <T>(output);

            // Backreference
            output.SourceAdapter = this;

            // Subscribe to collection / property change
            CollectionChangedEventManager.AddListener(input1.InnerAsNotifier, this);
            CollectionChangedEventManager.AddListener(input2.InnerAsNotifier, this);

            // Evaluate changes
            ReEvaluate();
        }
Пример #19
0
 public InputCollectionWrapper(ObservableCollection <T> inner)
 {
     _inner     = inner;
     _innerAsCC = inner as LinqContinuousCollection <T>;
 }