Example #1
0
 /// <summary>
 /// Makes a typed comparer from the given comparer.
 /// </summary>
 /// <typeparam name="T">The type of items the comparer should compare.</typeparam>
 /// <param name="comparer">The comparer to convert to a typed comparer.</param>
 /// <returns>A typed comparer.</returns>
 /// <exception cref="System.ArgumentNullException">The comparer is null.</exception>
 public static IComparer <T> Typed <T>(this IComparer comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     return(TypedComparer <T> .GetComparer(comparer));
 }
Example #2
0
        public static IComparer GetComparer(IComparer <T> comparer)
        {
            TypedComparer <T> typed = comparer as TypedComparer <T>;

            if (typed != null)
            {
                return(typed.Comparer);
            }
            IComparer untyped = comparer as IComparer;

            if (untyped != null)
            {
                return(untyped);
            }
            return(new UntypedComparer <T>(comparer));
        }