コード例 #1
0
        // Token: 0x060075B3 RID: 30131 RVA: 0x00219A70 File Offset: 0x00217C70
        internal int CompareLiveShapingItems(LiveShapingItem x, LiveShapingItem y)
        {
            if (x == y || ItemsControl.EqualsEx(x.Item, y.Item))
            {
                return(0);
            }
            int num = 0;

            if (!this._isCustomSorting)
            {
                SortFieldComparer         sortFieldComparer = this._comparer as SortFieldComparer;
                SortDescriptionCollection sortDescriptions  = ((ICollectionView)this.View).SortDescriptions;
                int num2 = this._compInfos.Length;
                for (int i = 0; i < num2; i++)
                {
                    object value  = x.GetValue(this._compInfos[i].Path, this._compInfos[i].Property);
                    object value2 = y.GetValue(this._compInfos[i].Path, this._compInfos[i].Property);
                    num = sortFieldComparer.BaseComparer.Compare(value, value2);
                    if (sortDescriptions[i].Direction == ListSortDirection.Descending)
                    {
                        num = -num;
                    }
                    if (num != 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                num = this._comparer.Compare(x.Item, y.Item);
            }
            return(num);
        }
コード例 #2
0
        // Helper method for sorting an ArrayList.  If the comparer is a SortFieldComparer,
        // use the cached-value approach to avoid excessive reflection.  For other
        // comparers, sort the usual way
        internal static void SortHelper(ArrayList al, IComparer comparer)
        {
            SortFieldComparer sfc = comparer as SortFieldComparer;

            if (sfc == null)
            {
                // sort the usual way
                al.Sort(comparer);
            }
            else
            {
                // Sort with cached values.
                // Step 1.  Copy the items into a list augmented with slots for
                // the cached values.
                int n                  = al.Count;
                int nFields            = sfc._fields.Length;
                CachedValueItem[] list = new CachedValueItem[n];
                for (int i = 0; i < n; ++i)
                {
                    list[i].Initialize(al[i], nFields);
                }

                // Step 2. Sort the augmented list.  The SortFieldComparer will
                // fill in the slots as necessary to perform its comparisons.
                Array.Sort(list, sfc);

                // Step 3. Copy the items back into the original list, now in
                // sorted order
                for (int i = 0; i < n; ++i)
                {
                    al[i] = list[i].OriginalItem;
                }
            }
        }
コード例 #3
0
        // Sort the list, according to the comparer
        internal static void Sort(this IList list, IComparer comparer)
        {
            ArrayList       al;
            LiveShapingList lsList;

            if ((al = list as ArrayList) != null)
            {
                SortFieldComparer.SortHelper(al, comparer);
            }
            else if ((lsList = list as LiveShapingList) != null)
            {
                lsList.Sort();
            }
        }
コード例 #4
0
        // Token: 0x060074CC RID: 29900 RVA: 0x00216868 File Offset: 0x00214A68
        internal static void Sort(this IList list, IComparer comparer)
        {
            ArrayList al;

            if ((al = (list as ArrayList)) != null)
            {
                SortFieldComparer.SortHelper(al, comparer);
                return;
            }
            LiveShapingList liveShapingList;

            if ((liveShapingList = (list as LiveShapingList)) != null)
            {
                liveShapingList.Sort();
            }
        }
コード例 #5
0
        internal int CompareLiveShapingItems(LiveShapingItem x, LiveShapingItem y)
        {
            #if LiveShapingInstrumentation
            ++_comparisons;
            #endif

            if (x == y || Object.Equals(x.Item, y.Item))
            {
                return(0);
            }

            int result = 0;

            if (!_isCustomSorting)
            {
                // intercept SortFieldComparer, and do the comparisons here.
                // The LiveShapingItems will cache the field values.
                SortFieldComparer         sfc = _comparer as SortFieldComparer;
                SortDescriptionCollection sdc = ((ICollectionView)View).SortDescriptions;
                Debug.Assert(sdc.Count >= _compInfos.Length, "SortDescriptions don't match LivePropertyInfos");
                int n = _compInfos.Length;

                for (int k = 0; k < n; ++k)
                {
                    object v1 = x.GetValue(_compInfos[k].Path, _compInfos[k].Property);
                    object v2 = y.GetValue(_compInfos[k].Path, _compInfos[k].Property);

                    result = sfc.BaseComparer.Compare(v1, v2);
                    if (sdc[k].Direction == ListSortDirection.Descending)
                    {
                        result = -result;
                    }

                    if (result != 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                // for custom comparers, just compare items the normal way
                result = _comparer.Compare(x.Item, y.Item);
            }

            return(result);
        }
コード例 #6
0
        // Token: 0x060076CF RID: 30415 RVA: 0x0021F504 File Offset: 0x0021D704
        internal static void SortHelper(ArrayList al, IComparer comparer)
        {
            SortFieldComparer sortFieldComparer = comparer as SortFieldComparer;

            if (sortFieldComparer == null)
            {
                al.Sort(comparer);
                return;
            }
            int count   = al.Count;
            int nFields = sortFieldComparer._fields.Length;

            SortFieldComparer.CachedValueItem[] array = new SortFieldComparer.CachedValueItem[count];
            for (int i = 0; i < count; i++)
            {
                array[i].Initialize(al[i], nFields);
            }
            Array.Sort(array, sortFieldComparer);
            for (int j = 0; j < count; j++)
            {
                al[j] = array[j].OriginalItem;
            }
        }
コード例 #7
0
        // build the shaping information from the relevant properties
        private void PrepareShaping()
        {
            // sort:  prepare the comparer
            if (_customSort != null)
            {
                ActiveComparer = _customSort;
            }
            else if (_sort != null && _sort.Count > 0)
            {
                IComparer xmlComparer = SystemXmlHelper.PrepareXmlComparer(SourceCollection, _sort, Culture);
                if (xmlComparer!= null)
                {
                    ActiveComparer = xmlComparer;
                }
                else
                {
                    ActiveComparer = new SortFieldComparer(_sort, Culture);
                }
            }
            else
            {
                ActiveComparer = null;
            }

            // filter:  prepare the Predicate<object> filter
            ActiveFilter = Filter;

            // group : prepare the group descriptions

            // discard old groups
            _group.Clear();

            // initialize the synthetic top level group
            _group.Initialize();

            _isGrouping = (_group.GroupBy != null);
        }
コード例 #8
0
        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------

        #region Protected Methods

        /// <summary>
        /// Re-create the view over the associated IList
        /// </summary>
        /// <remarks>
        /// Any sorting and filtering will take effect during Refresh.
        /// </remarks>
        protected override void RefreshOverride()
        {
            object oldCurrentItem = CurrentItem;
            int oldCurrentPosition = IsEmpty ? 0 : CurrentPosition;
            bool oldIsCurrentAfterLast = IsCurrentAfterLast;
            bool oldIsCurrentBeforeFirst = IsCurrentBeforeFirst;

            // force currency off the collection (gives user a chance to save dirty information)
            OnCurrentChanging();

            // changing filter and sorting will cause the inner IBindingList(View) to
            // raise refresh action; ignore those until done setting filter/sort
            _ignoreInnerRefresh = true;

            // IBindingListView can support filtering
            if (IsCustomFilterSet || _isFiltered)
            {
                BindingOperations.AccessCollection(InternalList,
                    () =>
                    {
                        if (IsCustomFilterSet)
                        {
                            _isFiltered = true;
                            _blv.Filter = _customFilter;
                        }
                        else if (_isFiltered)
                        {
                            // app has cleared filter
                            _isFiltered = false;
                            _blv.RemoveFilter();
                        }
                    },
                    true);
            }

            if ((_sort != null) && (_sort.Count > 0) && (CollectionProxy != null) && (CollectionProxy.Count > 0))
            {
                // convert Avalon SortDescription collection to .Net
                // (i.e. string property names become PropertyDescriptors)
                ListSortDescriptionCollection sorts = ConvertSortDescriptionCollection(_sort);

                if (sorts.Count > 0)
                {
                    _isSorted = true;
                    BindingOperations.AccessCollection(InternalList,
                        () =>
                        {
                            if (_blv == null)
                                InternalList.ApplySort(sorts[0].PropertyDescriptor, sorts[0].SortDirection);
                            else
                                _blv.ApplySort(sorts);
                        },
                        true);
                }
                ActiveComparer = new SortFieldComparer(_sort, Culture);
            }
            else if (_isSorted)
            {
                // undo any previous sorting
                _isSorted = false;
                BindingOperations.AccessCollection(InternalList,
                    () =>
                    {
                        InternalList.RemoveSort();
                    },
                    true);
                ActiveComparer = null;
            }

            InitializeGrouping();

            // refresh cached list with any changes
            PrepareCachedList();

            PrepareGroups();

            // reset currency
            if (oldIsCurrentBeforeFirst || IsEmpty)
            {
                SetCurrent(null, -1);
            }
            else if (oldIsCurrentAfterLast)
            {
                SetCurrent(null, InternalCount);
            }
            else
            {
                // oldCurrentItem may be null

                // if there are duplicates, use the position of the first matching item
                //ISSUE windows#868101 DataRowView.IndexOf(oldCurrentItem) returns wrong index, wrong current item gets restored
                int newPosition = InternalIndexOf(oldCurrentItem);

                if (newPosition < 0)
                {
                    // oldCurrentItem not found: move to first item
                    object newItem;
                    newPosition = (NewItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning) ?
                                1 : 0;
                    if (newPosition < InternalCount && (newItem = InternalItemAt(newPosition)) != NewItemPlaceholder)
                    {
                        SetCurrent(newItem, newPosition);
                    }
                    else
                    {
                        SetCurrent(null, -1);
                    }
                }
                else
                {
                    SetCurrent(oldCurrentItem, newPosition);
                }
            }

            _ignoreInnerRefresh = false;

            // tell listeners everything has changed
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

            OnCurrentChanged();

            if (IsCurrentAfterLast != oldIsCurrentAfterLast)
                OnPropertyChanged(IsCurrentAfterLastPropertyName);

            if (IsCurrentBeforeFirst != oldIsCurrentBeforeFirst)
                OnPropertyChanged(IsCurrentBeforeFirstPropertyName);

            if (oldCurrentPosition != CurrentPosition)
                OnPropertyChanged(CurrentPositionPropertyName);

            if (oldCurrentItem != CurrentItem)
                OnPropertyChanged(CurrentItemPropertyName);
        }
コード例 #9
0
        // build the sort and filter information from the relevant properties
        private void PrepareSortAndFilter(IList list)
        { 
            // sort:  prepare the comparer
            if (_customSort != null) 
            { 
                ActiveComparer = _customSort;
            } 
            else if (_sort != null && _sort.Count > 0)
            {
                IComparer xmlComparer;
                if (AssemblyHelper.IsLoaded(UncommonAssembly.System_Xml) && 
                    (xmlComparer = PrepareXmlComparer(SourceCollection)) != null)
                { 
                    ActiveComparer = xmlComparer; 
                }
                else 
                {
                    ActiveComparer = new SortFieldComparer(_sort, Culture);
                }
            } 
            else
            { 
                ActiveComparer = null; 
            }
 
            // filter:  prepare the Predicate<object> filter
            ActiveFilter = Filter;
        }