コード例 #1
0
        public IEnumerable <object> Sort(string columnName, IEnumerable <object> items)
        {
            if (columnName != _activeSortColumn)
            {
                items = items.OrderBy(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList();
                _isSortedAscending = true;
                _activeSortColumn  = columnName;
            }
            else
            {
                if (_isSortedAscending)
                {
                    items = items.OrderByDescending(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList();
                }
                else
                {
                    items = items.OrderBy(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList();
                }
                _isSortedAscending = !_isSortedAscending;
            }

            Sorted?.Invoke(items);

            return(items);
        }
コード例 #2
0
    /// <summary>
    /// Sorts the elements in a range of elements in list.
    /// </summary>
    /// <param name="index">The zero-based starting index of the range to sort.</param>
    /// <param name="count">The length of the range to sort.</param>
    /// <param name="comparer">The optional comparer implementation to use when comparing elements.</param>
    /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception>
    /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list. -or- The implementation of comparer caused an error during the sort.</exception>
    /// <exception cref="InvalidOperationException">comparer is null, and the default comparer cannot find implementation.</exception>
    public void Sort(int index = 0, int?count = null, IComparer <T> comparer = null)
    {
        if (!count.HasValue)
        {
            slim.EnterWriteLock();
            try
            {
                list.Sort(index, list.Count - index, comparer);
            }
            finally
            {
                slim.ExitWriteLock();
            }

            Sorted?.Invoke(this, new EventArgs());
            return;
        }

        slim.EnterWriteLock();
        try
        {
            list.Sort(index, count.Value, comparer);
        }
        finally
        {
            slim.ExitWriteLock();
        }

        Sorted?.Invoke(this, new EventArgs());
    }
コード例 #3
0
    /// <summary>
    /// Reverses the order of the elements in the specified range.
    /// </summary>
    /// <param name="index">The zero-based starting index of the range to reverse.</param>
    /// <param name="count">The number of elements in the range to reverse.</param>
    /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception>
    /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list.</exception>
    public void Reverse(int index = 0, int?count = null)
    {
        if (!count.HasValue)
        {
            slim.EnterWriteLock();
            try
            {
                list.Reverse(index, list.Count - index);
            }
            finally
            {
                slim.ExitWriteLock();
            }

            Sorted?.Invoke(this, new EventArgs());
            return;
        }

        slim.EnterWriteLock();
        try
        {
            list.Reverse(index, count.Value);
        }
        finally
        {
            slim.ExitWriteLock();
        }

        Sorted?.Invoke(this, new EventArgs());
    }
コード例 #4
0
 /// <summary>
 /// Raises event 'Sorted'
 /// </summary>
 protected virtual void OnSorted()
 {
     if (Sorted != null)
     {
         Sorted.Invoke(this, System.EventArgs.Empty);
     }
 }
コード例 #5
0
        public void Sort()
        {
            Items = Items
                    .OrderBy(item => item.IsEmpty)
                    .ThenByDescending(item => item.IsArmor || item.IsWeapon || item.IsJewelry)
                    .ThenByDescending(item => item.Type?.Type)
                    .ThenBy(item => item.Rarity?.Type)
                    .ThenBy(item => item.Name)
                    .ToList();

            Sorted?.Invoke(this);
        }
コード例 #6
0
ファイル: ConcurrentList.cs プロジェクト: nuscien/trivial
    /// <summary>
    /// Sorts the elements in a range of elements in list.
    /// </summary>
    /// <param name="index">The zero-based starting index of the range to sort.</param>
    /// <param name="count">The length of the range to sort.</param>
    /// <param name="comparer">The optional comparer implementation to use when comparing elements.</param>
    /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception>
    /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list. -or- The implementation of comparer caused an error during the sort.</exception>
    /// <exception cref="InvalidOperationException">comparer is null, and the default comparer cannot find implementation.</exception>
    public void Sort(int index = 0, int?count = null, IComparer <T> comparer = null)
    {
        if (!count.HasValue)
        {
            lock (locker)
            {
                list.Sort(index, list.Count - index, comparer);
            }

            Sorted?.Invoke(this, new EventArgs());
            return;
        }

        lock (locker)
        {
            list.Sort(index, count.Value, comparer);
        }

        Sorted?.Invoke(this, new EventArgs());
    }
コード例 #7
0
ファイル: ConcurrentList.cs プロジェクト: nuscien/trivial
    /// <summary>
    /// Reverses the order of the elements in the specified range.
    /// </summary>
    /// <param name="index">The zero-based starting index of the range to reverse.</param>
    /// <param name="count">The number of elements in the range to reverse.</param>
    /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception>
    /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list.</exception>
    public void Reverse(int index = 0, int?count = null)
    {
        if (!count.HasValue)
        {
            lock (locker)
            {
                list.Reverse(index, list.Count - index);
            }

            Sorted?.Invoke(this, new EventArgs());
            return;
        }

        lock (locker)
        {
            list.Reverse(index, count.Value);
        }

        Sorted?.Invoke(this, new EventArgs());
    }
コード例 #8
0
 protected void OnSorted()
 {
     Sorted?.Invoke(this, new EventArgs());
 }
コード例 #9
0
 /// <summary>
 /// Raises the Sorted event.
 /// </summary>
 /// <param name="e">A SortedEventArgs that contains the event data.</param>
 protected virtual void OnSorted(SortedEventArgs e)
 {
     Sorted?.Invoke(this, e);
 }