Example #1
0
        /// <summary>
        /// Construct a sorter.
        /// </summary>
        /// <param name="keyGetter">The function that extracts a key from items in the list.</param>
        /// <param name="collection">The collection to be sorted.</param>
        /// <param name="dispatcher">The dispatcher on which move operations can be performed.</param>
        /// <param name="orderCheckTriggerProperties">The names of the properties of items that cause ordering to be checked when they change.</param>
        /// <param name="collectionAccessMediator">An object capable of preventing concurrent access to the target collection while the sorter performs the initial sort.</param>
        public CollectionAutoSorter(Func <TItem, TKey> keyGetter, ObservableCollection <TItem> collection, Dispatcher dispatcher, IEnumerable <string> orderCheckTriggerProperties, IObservableCollectionAccessMediator collectionAccessMediator, bool orderDescending)
        {
            _keyGetter  = keyGetter;
            _collection = collection;
            _dispatcher = dispatcher;

            _collection.CollectionChanged += HandleCollectionChanged;
            _order = new CollectionOrder <TItem, TKey>(keyGetter, collection, dispatcher, orderCheckTriggerProperties, orderDescending);
            _order.LoadKeysAndTriggerArrange(collection, collectionAccessMediator);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the IEnumerable_Test.
        /// </summary>
        /// <param name="collection">The collection to run the tests on.</param>
        /// <param name="items">The items currently in the collection.</param>
        /// <param name="modifyCollection">Modifies the collection to invalidate the enumerator.</param>
        public IEnumerable_Test(IEnumerable collection, Object[] items, ModifyUnderlyingCollection modifyCollection)
        {
            _collection = collection;
            _modifyCollection = modifyCollection;
            _isGenericCompatibility = false;
            _isResetNotSupported = false;
            _verificationLevel = VerificationLevel.Extensive;
            _collectionOrder = CollectionOrder.Sequential;

            if (items == null)
                _items = new Object[0];
            else
                _items = items;

            _comparer = System.Collections.Generic.EqualityComparer<Object>.Default;
        }
Example #3
0
        /// <summary>
        /// Specify a function that extracts a sortable key from object instances, that can be used to order items in the view.
        ///
        /// The ordering of the view will be checked whenever one of the items raises a property changed event
        /// (see <see cref="INotifyPropertyChanged"/>) for one of a set of specified properties. Only the position of the element
        /// raising the event will be considered.
        ///
        /// When new items are added to the collection, the function will be used to select an appropriate position
        /// in the view.
        /// </summary>
        /// <param name="function">The function that gets the sort key from an instance of <see cref="T"/>.</param>
        /// <param name="orderCheckPropertyNames">The names of the properties that should trigger a check.</param>
        public void OrderBy <TKey>(Func <T, TKey> function, IEnumerable <string> orderCheckPropertyNames, bool orderDescending) where TKey : IComparable
        {
            if (_mediator == null)
            {
                throw new MediatorNotSetException();
            }

            if (_collectionOrder != null)
            {
                _collectionOrder.Detach();
            }

            var order = new CollectionOrder <T, TKey>(function, View, _dispatcher, orderCheckPropertyNames, orderDescending);

            order.LoadKeysAndTriggerArrange(_target, _mediator);
            _collectionOrder = order;
        }
        /// <summary>
        /// Specify a function that extracts a sortable key from object instances, that can be used to order items in the view.
        ///
        /// The ordering of the view will be checked whenever one of the items raises a property changed event
        /// (see <see cref="INotifyPropertyChanged"/>) for one of a set of specified properties. Only the position of the element
        /// raising the event will be considered.
        ///
        /// When new items are added to the collection, the function will be used to select an appropriate position
        /// in the view.
        /// </summary>
        /// <param name="function">The function that gets the sort key from an instance of <see cref="T"/>.</param>
        /// <param name="orderCheckPropertyNames">The names of the properties that should trigger a check.</param>
        /// <param name="orderDescending">True if the sort order is to be descending instead of ascending</param>
        public void OrderBy <TKey>(Func <TItem, TKey> function, IEnumerable <string> orderCheckPropertyNames, bool orderDescending) where TKey : IComparable
        {
            _log.LazyAdd("Set Order {0}", new Lazy <string>(function.ToString), new Lazy <string>(() => orderCheckPropertyNames.Aggregate((t, i) => t + "," + i)));
            if (_mediator == null)
            {
                throw new MediatorNotSetException();
            }

            if (_collectionOrder != null)
            {
                _collectionOrder.Detach();
            }

            var order = new CollectionOrder <TItem, TKey>(function, View, _dispatcher, orderCheckPropertyNames, orderDescending);

            order.LoadKeysAndTriggerArrange(View, _mediator);
            _collectionOrder = order;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the IEnumerable_Test.
        /// </summary>
        /// <param name="collection">The collection to run the tests on.</param>
        /// <param name="items">The items currently in the collection.</param>
        /// <param name="modifyCollection">Modifies the collection to invalidate the enumerator.</param>
        public IEnumerable_Test(IEnumerable collection, Object[] items, ModifyUnderlyingCollection modifyCollection)
        {
            _collection             = collection;
            _modifyCollection       = modifyCollection;
            _isGenericCompatibility = false;
            _isResetNotSupported    = false;
            _verificationLevel      = VerificationLevel.Extensive;
            _collectionOrder        = CollectionOrder.Sequential;

            if (items == null)
            {
                _items = new Object[0];
            }
            else
            {
                _items = items;
            }

            _comparer = System.Collections.Generic.EqualityComparer <Object> .Default;
        }
            /// <summary>
            /// Initializes a new instance of the IEnumerable_T_Test.
            /// </summary>
            /// <param name="collection">The collection to run the tests on.</param>
            /// <param name="items"></param>
            /// <param name="modifyCollection"></param>
            public IEnumerable_T_Test(Test test, IEnumerable <T> collection, T[] items, ModifyUnderlyingCollection_T <T> modifyCollection)
            {
                m_test               = test;
                _collection          = collection;
                _modifyCollection    = modifyCollection;
                _verificationLevel   = VerificationLevel.Extensive;
                _collectionOrder     = CollectionOrder.Sequential;
                _converter           = null;
                _isResetNotSupported = false;
                _moveNextAtEndThrowsOnModifiedCollection = true;

                if (items == null)
                {
                    _items = new T[0];
                }
                else
                {
                    _items = items;
                }

                _comparer = EqualityComparer <T> .Default;
            }