using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Framework.Systems
{
public class CommonEqualityComparer<T> : IEqualityComparer<T> where T:class
{
private Func<T,T, bool> predicate;
public CommonEqualityComparer(Func<T,T, bool> predicate)
{
this.predicate = predicate;
}
public bool Equals(T x, T y)
{
return predicate(x, y);
}
public int GetHashCode(T obj)
{
var fromProperties = TypeDescriptor.GetProperties(obj);
StringBuilder builder = new StringBuilder();
foreach (PropertyDescriptor property in fromProperties)
{
object oldValue = property.GetValue(obj);
if(oldValue!=null)
builder.Append(oldValue.ToString());
}
return builder.ToString().GetHashCode();
}
}
}
CommonEqualityComparer<T>
最新推荐文章于 2021-06-26 00:32:46 发布