2009-08-06 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / Mono.C5 / C5 / Comparer.cs
index c8cf8a6ca1018827f21fc2bd52fd83ce7edee60b..8b68baebe839a7d62c1b683e58b334b367810836 100644 (file)
@@ -1,4 +1,3 @@
-#if NET_2_0\r
 /*\r
  Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft\r
  Permission is hereby granted, free of charge, to any person obtaining a copy\r
@@ -28,11 +27,11 @@ using System.Diagnostics;
 using SCG = System.Collections.Generic;\r
 \r
 namespace C5\r
-{ \r
-/// <summary>\r
-/// A default item comparer for an item type that is either generic (IComparable&lt;T&gt;)\r
-/// or ordinarily (System.IComparable) comparable.\r
-/// </summary>\r
+{\r
+  /// <summary>\r
+  /// A default item comparer for an item type that is either generic (IComparable&lt;T&gt;)\r
+  /// or ordinarily (System.IComparable) comparable.\r
+  /// </summary>\r
   public static class Comparer<T>\r
   {\r
     readonly static Type naturalComparerO = typeof(NaturalComparerO<>);\r
@@ -62,14 +61,41 @@ namespace C5
 \r
         if (t.IsValueType)\r
         {\r
+          if (t.Equals(typeof(char)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new CharComparer());\r
+\r
+          if (t.Equals(typeof(sbyte)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new SByteComparer());\r
+\r
+          if (t.Equals(typeof(byte)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new ByteComparer());\r
+\r
+          if (t.Equals(typeof(short)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new ShortComparer());\r
+\r
+          if (t.Equals(typeof(ushort)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new UShortComparer());\r
+\r
           if (t.Equals(typeof(int)))\r
             return cachedComparer = (SCG.IComparer<T>)(new IntComparer());\r
 \r
+          if (t.Equals(typeof(uint)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new UIntComparer());\r
+\r
+          if (t.Equals(typeof(long)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new LongComparer());\r
+\r
+          if (t.Equals(typeof(ulong)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new ULongComparer());\r
+\r
+          if (t.Equals(typeof(float)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new FloatComparer());\r
+\r
           if (t.Equals(typeof(double)))\r
             return cachedComparer = (SCG.IComparer<T>)(new DoubleComparer());\r
 \r
-          if (t.Equals(typeof(byte)))\r
-            return cachedComparer = (SCG.IComparer<T>)(new ByteComparer());\r
+          if (t.Equals(typeof(decimal)))\r
+            return cachedComparer = (SCG.IComparer<T>)(new DecimalComparer());\r
         }\r
 \r
         if (typeof(IComparable<T>).IsAssignableFrom(t))\r
@@ -95,6 +121,7 @@ namespace C5
   /// A natural generic IComparer for an IComparable&lt;T&gt; item type\r
   /// </summary>\r
   /// <typeparam name="T"></typeparam>\r
+  [Serializable]\r
   public class NaturalComparer<T> : SCG.IComparer<T>\r
       where T : IComparable<T>\r
   {\r
@@ -112,8 +139,8 @@ namespace C5
   /// A natural generic IComparer for a System.IComparable item type\r
   /// </summary>\r
   /// <typeparam name="T"></typeparam>\r
-  public class NaturalComparerO<T> : SCG.IComparer<T>\r
-      where T : System.IComparable\r
+  [Serializable]\r
+  public class NaturalComparerO<T> : SCG.IComparer<T> where T : System.IComparable\r
   {\r
     /// <summary>\r
     /// Compare two items\r
@@ -129,6 +156,7 @@ namespace C5
   /// A generic comparer for type T based on a Comparison[T] delegate\r
   /// </summary>\r
   /// <typeparam name="T"></typeparam>\r
+  [Serializable]\r
   public class DelegateComparer<T> : SCG.IComparer<T>\r
   {\r
     readonly Comparison<T> cmp;\r
@@ -150,5 +178,4 @@ namespace C5
     /// <returns>item1 &lt;=&gt; item2</returns>\r
     public int Compare(T item1, T item2) { return cmp(item1, item2); }\r
   }\r
-}\r
-#endif\r
+}
\ No newline at end of file