-#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
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<T>)\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<T>)\r
+ /// or ordinarily (System.IComparable) comparable.\r
+ /// </summary>\r
public static class Comparer<T>\r
{\r
readonly static Type naturalComparerO = typeof(NaturalComparerO<>);\r
\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
/// A natural generic IComparer for an IComparable<T> 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
/// 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
/// 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
/// <returns>item1 <=> 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