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();
            }
  • 相关阅读:
    jsp转向
    什么是 XDoclet?
    tomcat中的几点配置说明
    mysql5问题
    POJ 3734 Blocks
    POJ 2409 Let it Bead
    HDU 1171 Big Event in HDU
    POJ 3046 Ant Counting
    HDU 2082 找单词
    POJ 1286 Necklace of Beads
  • 原文地址:https://www.cnblogs.com/yeagen/p/13557529.html
Copyright © 2011-2022 走看看