2 using System.Collections;
4 namespace System.Data.Common
7 /// Summary description for ComparerFactory.
9 internal class DBComparerFactory
11 private static IComparer comparableComparer = new ComparebleComparer();
12 private static IComparer ignoreCaseComparer = new IgnoreCaseComparer();
13 private static IComparer caseComparer = new CaseComparer();
14 private static IComparer byteArrayComparer = new ByteArrayComparer();
15 private static Type icomparerType = typeof (IComparable);
17 public static IComparer GetComparer (Type type, bool ignoreCase)
19 if (type == typeof (string)) {
21 return ignoreCaseComparer;
24 if (icomparerType.IsAssignableFrom(type))
25 return comparableComparer;
26 if (type == typeof (byte[]))
27 return byteArrayComparer;
31 class ComparebleComparer :IComparer
33 #region IComparer Members
35 public int Compare(object x, object y)
37 if (x == DBNull.Value) {
38 if (y == DBNull.Value)
44 if (y == DBNull.Value)
47 return ((IComparable)x).CompareTo (y);
53 class CaseComparer : IComparer
55 #region IComparer Members
57 public int Compare(object x, object y)
59 if (x == DBNull.Value) {
60 if (y == DBNull.Value)
66 if (y == DBNull.Value)
69 return String.Compare ((string)x, (string)y, false);
75 class IgnoreCaseComparer : IComparer
77 #region IComparer Members
79 public int Compare(object x, object y)
81 if (x == DBNull.Value) {
82 if (y == DBNull.Value)
88 if (y == DBNull.Value)
91 return String.Compare ((string)x, (string)y, true);
97 class ByteArrayComparer : IComparer
99 #region IComparer Members
101 public int Compare(object x, object y)
103 if (x == DBNull.Value) {
104 if (y == DBNull.Value)
110 if (y == DBNull.Value)
113 byte[] o1 = (byte[])x;
114 byte[] o2 = (byte[])y;
116 int lenb = o2.Length;
118 for (int i = 0; ; i++) {
125 else if (i >= lenb) {