/// <summary>
        /// LINQ's ThenBy operator for generic EnumerableRowCollection.
        /// </summary>
        public static OrderedEnumerableRowCollection <TRow> ThenBy <TRow, TKey>(this OrderedEnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer)
        {
            IEnumerable <TRow> ie = Enumerable.ThenBy((IOrderedEnumerable <TRow>)source.EnumerableRows, keySelector, comparer);
            OrderedEnumerableRowCollection <TRow> edt = new OrderedEnumerableRowCollection <TRow>(source, ie);

            edt.AddSortExpression(keySelector, comparer, isDescending: false, isOrderBy: false);
            return(edt);
        }
        /// <summary>
        /// LINQ's OrderByDescending operator for generic EnumerableRowCollection.
        /// </summary>
        public static OrderedEnumerableRowCollection <TRow> OrderByDescending <TRow, TKey>(this EnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer)
        {
            IEnumerable <TRow> ie = Enumerable.OrderByDescending(source, keySelector, comparer);

            OrderedEnumerableRowCollection <TRow> edt = new OrderedEnumerableRowCollection <TRow>(source, ie);

            edt.AddSortExpression(keySelector, comparer, isDescending: true, isOrderBy: true);
            return(edt);
        }
示例#3
0
        /// <summary>
        /// LINQ's OrderBy operator for generic EnumerableRowCollection.
        /// </summary>
        public static OrderedEnumerableRowCollection <TRow> OrderBy <TRow, TKey>(
            this EnumerableRowCollection <TRow> source,
            Func <TRow, TKey> keySelector)
        {
            IEnumerable <TRow> ie = Enumerable.OrderBy <TRow, TKey>(source, keySelector);

            OrderedEnumerableRowCollection <TRow> edt = new OrderedEnumerableRowCollection <TRow>(source, ie);

            edt.AddSortExpression(keySelector, false, true);
            return(edt);
        }
示例#4
0
        /// <summary>
        /// LINQ's ThenByDescending operator for generic EnumerableRowCollection.
        /// </summary>
        public static OrderedEnumerableRowCollection <TRow> ThenByDescending <TRow, TKey>(
            this OrderedEnumerableRowCollection <TRow> source,
            Func <TRow, TKey> keySelector)
        {
            IEnumerable <TRow> ie =
                Enumerable.ThenByDescending <TRow, TKey>((IOrderedEnumerable <TRow>)source.EnumerableRows, keySelector);

            OrderedEnumerableRowCollection <TRow> edt =
                new OrderedEnumerableRowCollection <TRow>((EnumerableRowCollection <TRow>)source, ie);

            edt.AddSortExpression(keySelector, /*desc*/ true, false);
            return(edt);
        }
        public void ThenBy_AddSortExpressionValidation()
        {
            var(table, one, two, three) = InstantiateTable();

            // Order the EnumerableRowCollection
            OrderedEnumerableRowCollection <DataRow> orderedSource = table.Cast <DataRow>().OrderBy(row => int.Parse((string)row.ItemArray[0]));

            DataRow zero         = table.Rows.Add(0);
            var     orderedAgain = orderedSource.ThenBy(row => int.Parse((string)row.ItemArray[0]));

            Assert.Equal(new DataRow[] { zero, one, two, three }, orderedAgain);

            DataRow negative      = table.Rows.Add(-1);
            var     comparedAgain = orderedSource.ThenBy((row => row), new TestDataRowComparer <DataRow>());

            Assert.Equal(new DataRow[] { negative, zero, one, two, three }, comparedAgain);
        }
示例#6
0
 internal static OrderedEnumerableRowCollection <TRow> AddSort <TRow, TKey> (OrderedEnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer, bool descending)
 {
     source.source.Sorter.AddSort <TKey> (keySelector, comparer, descending);
     return(source);
 }
 public static OrderedEnumerableRowCollection <TRow> OrderByDescending <TRow, TKey> (this TypedTableBase <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer)
     where TRow : DataRow
 {
     return(OrderedEnumerableRowCollection <TRow> .Create <TRow, TKey> (source, keySelector, comparer, true));
 }
 public static OrderedEnumerableRowCollection <TRow> ThenByDescending <TRow, TKey> (this OrderedEnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer)
 {
     return(OrderedEnumerableRowCollection <TRow> .AddSort <TRow, TKey> (source, keySelector, comparer, true));
 }
 public static OrderedEnumerableRowCollection <TRow> ThenByDescending <TRow, TKey> (this OrderedEnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector)
 {
     return(ThenByDescending <TRow, TKey> (source, keySelector, Comparer <TKey> .Default));
 }
 public static OrderedEnumerableRowCollection <TRow> OrderBy <TRow, TKey> (this EnumerableRowCollection <TRow> source, Func <TRow, TKey> keySelector, IComparer <TKey> comparer)
 {
     return(OrderedEnumerableRowCollection <TRow> .Create <TRow, TKey> (source, keySelector, comparer, false));
 }