diff --git a/Falcon.SugarApi/ObjectComparer.cs b/Falcon.SugarApi/ObjectComparer.cs new file mode 100644 index 0000000..b2aa265 --- /dev/null +++ b/Falcon.SugarApi/ObjectComparer.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Falcon.SugarApi +{ + /// + /// 通用Object比较接口 + /// + /// 对象类型 + public class ObjectComparer:IEqualityComparer where T : class + { + /// + /// 比较两个对象是否相等 + /// + /// 对象1 + /// 对象2 + /// True相等,False不相等 + public virtual bool Equals(T? x,T? y) { + if(x == null && y == null) { + return true; + } + if(x == null || y == null) { + return false; + } + foreach(var p in typeof(T).GetProperties()) { + if(p.CanRead) { + var v1 = p.GetValue(x); + var v2 = p.GetValue(y); + if(v1!=v2) { + return false; + } + } + } + return true; + } + + /// + /// 获取对象HashCode + /// + /// 要获取的对象 + /// + /// + public int GetHashCode([DisallowNull] T obj) { + throw new NotImplementedException(); + } + } +}