Hi!
Wouldn't it be a good thing to replace the following method in EntityPropertyComparer.cs with something like thw ones below? This would allow to support complex objects and comparing things like "Customer.AddressIDSource.City" for exasmple, which is not the case at the moment.
Original code:
/// <summary>
/// Compares 2 objects by their properties, given on the constructor
/// </summary>
/// <param name="x">First value to compare</param>
/// <param name="y">Second value to compare</param>
/// <returns></returns>
public int Compare(object x, object y)
{
object a = x.GetType().GetProperty(PropertyName).GetValue(x, null);
object b = y.GetType().GetProperty(PropertyName).GetValue(y, null);
if ( a != null && b == null )
return 1;
if ( a == null && b != null )
return -1;
if ( a == null && b == null )
return 0;
return ((IComparable)a).CompareTo(b);
}
New code:
public object getObj(object x)
{
object a = string.Empty;
string[] PropertyParts;
char[] delimiterChars = { '.' };
PropertyParts = PropertyName.Split(delimiterChars);
foreach (string propertyPart in PropertyParts)
{
a = x.GetType().GetProperty(propertyPart).GetValue(x, null);
x = a;
}
return a;
}
/// <summary>
/// Compares 2 objects by their properties, given on the constructor
/// </summary>
/// <param name="x">First value to compare</param>
/// <param name="y">Second value to compare</param>
/// <returns></returns>
public int Compare(object x, object y)
{
//object a = x.GetType().GetProperty(PropertyName).GetValue(x, null);
//object b = y.GetType().GetProperty(PropertyName).GetValue(y, null);
object a = getObj(x);
object b = getObj(y);
if ( a != null && b == null )
return 1;
if ( a == null && b != null )
return -1;
if ( a == null && b == null )
return 0;
return ((IComparable)a).CompareTo(b);
}
Cheers!
JF