Merging changes
This commit is contained in:
1 parent
c4216d2272
commit
797816be7e
437 files changed
+54228
-28
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic IComparer for IBlueRow. Accepts a list of column names to define the sort order. All included columns must be IComparable.
|
||||
/// </summary>
|
||||
public class BlueRowComparer : IComparer<IBlueRow>, IComparer
|
||||
{
|
||||
private IEnumerable<string> myCompareColumns;
|
||||
private bool myIsAscending;
|
||||
|
||||
public BlueRowComparer(bool ascending, params string[] columns)
|
||||
{
|
||||
this.myCompareColumns = columns;
|
||||
this.myIsAscending = ascending;
|
||||
}
|
||||
|
||||
public BlueRowComparer(params string[] columns)
|
||||
: this(true, columns)
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(IBlueRow x, IBlueRow y)
|
||||
{
|
||||
// Guard against nulls
|
||||
if (x == y) return 0;
|
||||
if (x == null) return -1;
|
||||
if (y == null) return 1;
|
||||
|
||||
int result = 0;
|
||||
foreach (string compareColumn in this.myCompareColumns)
|
||||
{
|
||||
object left = x[compareColumn];
|
||||
object right = y[compareColumn];
|
||||
if (left == right) result = 0;
|
||||
else if (left == null || left == DBNull.Value) result = -1;
|
||||
else if (right == null || right == DBNull.Value) result = 1;
|
||||
else result = ((IComparable)left).CompareTo(right);
|
||||
if (result != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return result * (this.myIsAscending ? 1 : -1);
|
||||
}
|
||||
|
||||
#region IComparer Members
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
return this.Compare(x as IBlueRow, y as IBlueRow);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user