示例#1
0
        /// <summary>
        /// 按照指定的规则排序
        /// </summary>
        /// <param name="orderByProperty"></param>
        /// <param name="direction"></param>
        public void Sort(OrderByPropertyType orderByProperty, SortDirectionType direction)
        {
            T[] objArray = this.ToArray();

            Array.Sort(objArray, delegate(T x, T y)
            {
                int result = 0;

                switch (orderByProperty)
                {
                case OrderByPropertyType.FullPath:
                    result = x.FullPath.CompareTo(y.FullPath);
                    break;

                case OrderByPropertyType.GlobalSortID:
                    result = x.GlobalSortID.CompareTo(y.GlobalSortID);
                    break;

                case OrderByPropertyType.Name:
                    result = x.Name.CompareTo(y.Name);
                    break;
                }

                if (direction == SortDirectionType.Descending)
                {
                    result = -result;
                }

                return(result);
            });

            this.Clear();
            this.CopyFrom(objArray);
        }
示例#2
0
        /// <summary>
        /// 排序
        /// </summary>
        /// <param name="orderByProperty">排序属性,<seealso cref="OrderByPropertyType"/>。</param>
        /// <param name="direction">排序方式,<seealso cref="SortDirectionType"/>。</param>
        public void Sort(OrderByPropertyType orderByProperty, SortDirectionType direction)
        {
            T[] objArray = new T[this.Count];

            Items.CopyTo(objArray, 0);

            Array.Sort(objArray, delegate(T x, T y)
            {
                int result = 0;

                switch (orderByProperty)
                {
                case OrderByPropertyType.FullPath:
                    result = x.FullPath.CompareTo(y.FullPath);
                    break;

                case OrderByPropertyType.GlobalSortID:
                    result = x.GlobalSortID.CompareTo(y.GlobalSortID);
                    break;

                case OrderByPropertyType.Name:
                    result = x.Name.CompareTo(y.Name);
                    break;
                }

                if (direction == SortDirectionType.Descending)
                {
                    result = -result;
                }

                return(result);
            });

            Items.Clear();
            for (int i = 0; i < objArray.Length; i++)
            {
                Items.Add(objArray[i]);
            }
        }