91 lines
1.7 KiB
C#
91 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace CPF.ReoGrid
|
|
{
|
|
internal class CellComparer : IComparer<object>
|
|
{
|
|
public CellComparer(SortOrder order)
|
|
{
|
|
this.sign = ((order == SortOrder.Ascending) ? 1 : -1);
|
|
}
|
|
|
|
public int Compare(object x, object y)
|
|
{
|
|
IComparable comparable = x as IComparable;
|
|
string text = comparable as string;
|
|
bool flag = text != null && string.IsNullOrEmpty(text);
|
|
if (flag)
|
|
{
|
|
comparable = null;
|
|
}
|
|
string text2 = y as string;
|
|
bool flag2 = text2 != null && string.IsNullOrEmpty(text2);
|
|
if (flag2)
|
|
{
|
|
y = null;
|
|
}
|
|
bool flag3 = comparable == null && y == null;
|
|
int result;
|
|
if (flag3)
|
|
{
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
bool flag4 = comparable != null && y == null;
|
|
if (flag4)
|
|
{
|
|
result = -this.sign;
|
|
}
|
|
else
|
|
{
|
|
bool flag5 = comparable == null;
|
|
if (flag5)
|
|
{
|
|
result = this.sign;
|
|
}
|
|
else
|
|
{
|
|
bool flag6 = comparable.GetType() == y.GetType();
|
|
if (flag6)
|
|
{
|
|
result = comparable.CompareTo(y);
|
|
}
|
|
else
|
|
{
|
|
bool flag7 = y is string;
|
|
if (flag7)
|
|
{
|
|
result = Convert.ToString(comparable).CompareTo(y);
|
|
}
|
|
else
|
|
{
|
|
bool flag8 = comparable is string;
|
|
if (flag8)
|
|
{
|
|
result = comparable.CompareTo(Convert.ToString(y));
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
result = ((double)Convert.ChangeType(comparable, typeof(double))).CompareTo(Convert.ChangeType(y, typeof(double)));
|
|
}
|
|
catch
|
|
{
|
|
result = Convert.ToString(comparable).CompareTo(Convert.ToString(y));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private readonly int sign;
|
|
}
|
|
}
|