110,567
社区成员
发帖
与我相关
我的任务
分享
public class CusComparer<T> : IEqualityComparer<T> where T : class
{
#region IEqualityComparer<T> Members
public bool Equals(T x, T y)
{
foreach (var prop in typeof(T).GetProperties())
{
if (prop.GetValue(x, null) == prop.GetValue(y, null))
{
continue;
}
else
{
return false;
}
}
return true;
}
public int GetHashCode(T obj)
{
int hashcode = 0;
foreach (var prop in typeof(T).GetProperties())
{
hashcode ^= prop.GetValue(obj, null).GetHashCode();
}
return hashcode;
}
#endregion
}