{
private List
///
/// Creates a new instance of PropertyComparer.
///
/// The name of the property on type T
/// to perform the comparison on.
public GenericEqualityComparer()
{
var props = typeof(T).GetProperties(BindingFlags.GetProperty BindingFlags.Instance BindingFlags.Public);
_PropertyInfos.AddRange(props);
}
#region IEqualityComparer
public bool Equals(T x, T y)
{
foreach (var propertyInfo in _PropertyInfos)
{
//get the current value of the comparison property of x and of y
object xValue = propertyInfo.GetValue(x, null);
object yValue = propertyInfo.GetValue(y, null);
//if the xValue is null then we consider them equal if and only if yValue is null
if (xValue == null)
{
if (yValue != null)
return false;
}
if (!xValue.Equals(yValue))
return false;
}
return true;
}
public int GetHashCode(T obj)
{
List
`object`
values = new List
0 comments:
Post a Comment