public static IOrderedEnumerable <T> AndThen <T, TOrderBy>(this IOrderedEnumerable <T> original,
                                                                   Func <T, TOrderBy> selector) where TOrderBy : IComparable <TOrderBy>
        {
            IComparer <T> comparer = new SimpleComparer <T, TOrderBy>(selector);

            return(original.CreateSubOrder(comparer));
        }
        // We're continuing to require the ordered field to implement IComparable & are using the
        // SimpleComparer. A full implementation would allow us to pass something like a
        // Func<T, T, int> so we could specify an ordering function in the call
        public static IOrderedEnumerable <T> ProperOrder <T, TOrderBy>(this IEnumerable <T> original,
                                                                       Func <T, TOrderBy> selector) where TOrderBy : IComparable <TOrderBy>
        {
            IComparer <T> comparer = new SimpleComparer <T, TOrderBy>(selector);

            return(ProperOrderedCollection <T> .Create(original, comparer));
        }
Exemplo n.º 3
0
        public void Compare()
        {
            var Comparer = new SimpleComparer <string>((x, y) => string.Compare(x, y, System.StringComparison.Ordinal));

            Assert.Equal(0, Comparer.Compare("A", "A"));
            Assert.Equal(-1, Comparer.Compare("A", "B"));
            Assert.Equal(1, Comparer.Compare("B", "A"));
        }
 //зміна бінарного компаратора
 SimpleComparer ShiftBinaryComparer(SimpleComparer a)
 {
     if ((int)a == 0)
     {
         a = (SimpleComparer)3; return(a);
     }
     else
     {
         return(0);
     }
 }
 //зміна компаратора
 SimpleComparer ShiftComparer(SimpleComparer a)
 {
     if ((int)a == 5)
     {
         return(0);
     }
     else
     {
         return(++a);
     }
 }
Exemplo n.º 6
0
 static SimpleComparer()
 {
     ReadonlyInstance = new SimpleComparer();
 }
Exemplo n.º 7
0
 public SimpleComparerTests()
 {
     TestObject = new SimpleComparer <string>((x, y) => string.Compare(x, y, System.StringComparison.Ordinal));
 }