Beispiel #1
0
        public void OrderByIsCovariantTestWithCast()
        {
            var ordered = Enumerable.Range(0, 100).Select(i => i.ToString()).OrderBy(i => i.Length);

            System.Linq.IOrderedEnumerable <IComparable> covariantOrdered = ordered;
            covariantOrdered = covariantOrdered.ThenBy(i => i);
            string[] expected =
                Enumerable.Range(0, 100).Select(i => i.ToString()).OrderBy(i => i.Length).ThenBy(i => i).ToArray();
            Assert.Equal(expected, covariantOrdered);
        }
Beispiel #2
0
        public void SortsLargeDescendingEnumerableCorrectly()
        {
            const int         Items    = 1_000_000;
            IEnumerable <int> expected = NumberRangeGuaranteedNotCollectionType(0, Items);

            IEnumerable <int> unordered = expected.Select(i => Items - i - 1);

            System.Linq.IOrderedEnumerable <int> ordered = unordered.OrderBy(i => i);

            Assert.Equal(expected, ordered);
        }
        public static System.Linq.IOrderedEnumerable <TSource> ThenOrderByDescending <TSource, TKey>(
            this System.Linq.IOrderedEnumerable <TSource> source,
            params Func <TSource, TKey>[] keySelector)
        {
            if (keySelector.Length == 0)
            {
                throw new ArgumentException(nameof(keySelector));
            }

            System.Linq.IOrderedEnumerable <TSource> result = source;
            foreach (Func <TSource, TKey> ks in keySelector)
            {
                result = System.Linq.Enumerable.ThenByDescending(result, ks);
            }
            return(result);
        }
        public static System.Linq.IOrderedEnumerable <TSource> OrderByDescending <TSource, TKey>(
            this IEnumerable <TSource> source,
            params Func <TSource, TKey>[] keySelector)
        {
            if (keySelector.Length == 0)
            {
                throw new ArgumentException(nameof(keySelector));
            }

            System.Linq.IOrderedEnumerable <TSource> result = System.Linq.Enumerable.OrderByDescending(source, keySelector[0]);
            for (uint i = 1; i < keySelector.Length; ++i)
            {
                result = System.Linq.Enumerable.ThenByDescending(result, keySelector[i]);
            }
            return(result);
        }
Beispiel #5
0
        public static System.Linq.IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(
            this System.Linq.IOrderedEnumerable <TSource> source,
            Func <TSource, TKey> keySelector,
            IComparer <TKey> comparer)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }

            return(source.CreateOrderedEnumerable(keySelector, comparer, false));
        }
Beispiel #6
0
        public void SortsLargeDescendingEnumerableCorrectly(int thenBys)
        {
            const int         Items    = 100_000;
            IEnumerable <int> expected = NumberRangeGuaranteedNotCollectionType(0, Items);

            IEnumerable <int> unordered = expected.Select(i => Items - i - 1);

            System.Linq.IOrderedEnumerable <int> ordered = unordered.OrderBy(_ => 0);
            switch (thenBys)
            {
            case 1: ordered = ordered.ThenBy(i => i); break;

            case 2: ordered = ordered.ThenBy(i => 0).ThenBy(i => i); break;

            case 3: ordered = ordered.ThenBy(i => 0).ThenBy(i => 0).ThenBy(i => i); break;
            }

            Assert.Equal(expected, ordered);
        }
Beispiel #7
0
        public void SortsLargeRandomizedEnumerableCorrectly(int thenBys)
        {
            const int Items = 100_000;
            var       r     = new Random(42);

            int[] randomized = Enumerable.Range(0, Items).Select(i => r.Next()).ToArray();

            System.Linq.IOrderedEnumerable <int> orderedEnumerable = randomized.OrderBy(_ => 0);
            switch (thenBys)
            {
            case 1: orderedEnumerable = orderedEnumerable.ThenBy(i => i); break;

            case 2: orderedEnumerable = orderedEnumerable.ThenBy(i => 0).ThenBy(i => i); break;

            case 3: orderedEnumerable = orderedEnumerable.ThenBy(i => 0).ThenBy(i => 0).ThenBy(i => i); break;
            }
            int[] ordered = orderedEnumerable.ToArray();

            Array.Sort(randomized, (a, b) => a - b);
            Assert.Equal(randomized, orderedEnumerable);
        }
Beispiel #8
0
        public static System.Linq.IOrderedEnumerable <TSource> ThenByDescending <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, Func <TSource, TKey> keySelector, IComparer <TKey> comparer)
        {
            if (source == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
            }

            return(source.CreateOrderedEnumerable(keySelector, comparer, true));
        }
 // [Fact]
 public void NullSource()
 {
     System.Linq.IOrderedEnumerable <int> source = null;
     Assert.Throws <ArgumentNullException>("source", () => source.ThenByDescending(i => i));
 }
Beispiel #10
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenByDescending <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, System.Func <TSource, TKey> keySelector, System.Collections.Generic.IComparer <TKey> comparer)
 {
     return(default(System.Linq.IOrderedEnumerable <TSource>));
 }
Beispiel #11
0
        public static System.Linq.IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, Func <TSource, TKey> keySelector)
        {
            if (source == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
            }

            return(source.CreateOrderedEnumerable(keySelector, null, false));
        }
 // [Fact]
 public void NullSourceComparer()
 {
     System.Linq.IOrderedEnumerable <int> source = null;
     Assert.Throws <ArgumentNullException>("source", () => source.ThenBy(i => i, null));
 }
Beispiel #13
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenByDescending <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, System.Func <TSource, TKey> keySelector)
 {
     return(default(System.Linq.IOrderedEnumerable <TSource>));
 }
Beispiel #14
0
 public System.Collections.Generic.IEnumerable <DbUp.Engine.SqlScript> Filter(System.Linq.IOrderedEnumerable <DbUp.Engine.SqlScript> sorted, System.Collections.Generic.IEnumerable <DbUp.Engine.ExecutedSqlScript> executedScripts, DbUp.Support.ScriptNameComparer comparer, DbUp.Helpers.IHasher hasher)
 {
 }
Beispiel #15
0
        // https://stackoverflow.com/questions/9927871/need-an-example-on-how-to-get-preferred-language-from-accept-language-request-he
        private static void GetHeader(Microsoft.AspNetCore.Http.HttpContext context)
        {
            // RequestHeaders.AcceptLanguage P
            string header = context.Request.Headers["Accept-Language"];
            // string header = "en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2";

            string def =
                Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.ParseList(header.Split(';')).Sort(
                    delegate(StringWithQualityHeaderValue a, StringWithQualityHeaderValue b)
            {
                return(a.Quality.GetValueOrDefault(1).CompareTo(b.Quality.GetValueOrDefault(1)));
            }
                    )[0].ToString();


            Microsoft.Net.Http.Headers.StringWithQualityHeaderValue defLang =
                Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.ParseList(header.Split(';'))
                .OrderByDescending(x => x.Quality.GetValueOrDefault(1))
                .FirstOrDefault();

            // Microsoft.Net.Http.Headers.StringWithQualityHeaderValue.Parse(new StringSegment(v));



            // Query syntax
            //System.Linq.IOrderedEnumerable<System.Net.Http.Headers.StringWithQualityHeaderValue> languages1 =
            System.Net.Http.Headers.StringWithQualityHeaderValue defaultLanguage =
                (from headerParts in header.Split(',')
                 select System.Net.Http.Headers.StringWithQualityHeaderValue.Parse(headerParts) into acceptLanguages
                 orderby acceptLanguages.Quality.GetValueOrDefault(1) descending
                 select acceptLanguages
                ).FirstOrDefault();

            // Method syntax
            System.Linq.IOrderedEnumerable <System.Net.Http.Headers.StringWithQualityHeaderValue> languages = header.Split(',')
                                                                                                              .Select(System.Net.Http.Headers.StringWithQualityHeaderValue.Parse)
                                                                                                              .OrderByDescending(s => s.Quality.GetValueOrDefault(1));
        }
Beispiel #16
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, System.Func <TSource, TKey> keySelector)
 {
     throw null;
 }
Beispiel #17
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, Func <TSource, TKey> keySelector)
 {
     throw new NotImplementedException();
 }
Beispiel #18
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenByDescending <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, Func <TSource, TKey> keySelector, IComparer <TKey> comparer)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 public static System.Linq.IOrderedEnumerable <TSource> ThenBy <TSource, TKey>(this System.Linq.IOrderedEnumerable <TSource> source, System.Func <TSource, TKey> keySelector, System.Collections.Generic.IComparer <TKey> comparer)
 {
     throw null;
 }
Beispiel #20
0
 public static System.Linq.IOrderedEnumerable <TValue> ThenByDescending <TValue, TKey>(this System.Linq.IOrderedEnumerable <TValue> self, Func <TValue, TKey> keySelector)
 {
     return(System.Linq.Enumerable.ThenByDescending(self, keySelector));
 }