zoukankan      html  css  js  c++  java
  • 重写Equals的方式

            public override bool Equals(object obj)
            {
                //obj不为空
                if (obj == null)
                    return false;
                //是否同一个引用
                if (ReferenceEquals(this, obj))
                    return true;
                //是否不是聚合根
                IAggregateRoot ar = obj as IAggregateRoot;
                if (ar == null)
                    return false;
                //是否不是同一个类型
                var thisType = this.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? this.GetType().BaseType : this.GetType();
                var objType = obj.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? obj.GetType().BaseType : obj.GetType();
                if (thisType != objType)
                {
                    return false;
                }
    
                //Id是否相等
                return this.Id == ar.Id;
            }
    
            public override int GetHashCode()
            {
               var thisType = this.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? this.GetType().BaseType : this.GetType();
               string keyword = thisType.FullName + "|" + this.Id;
               return keyword.GetHashCode();
               //return this.Id.GetHashCode();
               //return base.GetHashCode();
            }
  • 相关阅读:
    JSON与JSONP的区别
    BFC(块级格式上下文)
    面试题--新
    javascript 类数组对象
    WebP 图片实践之路
    HTTP,HTTP2.0,SPDY,HTTPS你应该知道的一些事
    前端面试题目
    JS 中的事件设计
    博客声明
    1.2 线性表的链式表示
  • 原文地址:https://www.cnblogs.com/yeagen/p/13557529.html
Copyright © 2011-2022 走看看