Com.Aote.ObjectTools.GeneralObject.Equals C# (CSharp) Method

Equals() public method

重载对象相等方法,两个对象只要id号相同则相等。如果其中一个没有id号,则不相等。如果都没有id号,那么 只有引用相等时才相等。
public Equals ( object obj ) : bool
obj object 要比较的对象
return bool
        public override bool Equals(object obj)
        {
            //如果类型不同,或者对象为空,一定不相等
            if(obj == null || !(obj is GeneralObject))
            {
                return false;
            }
            GeneralObject go = obj as GeneralObject;
            object thisId = GetPropertyValue("id");
            object otherId = go.GetPropertyValue("id");
            //如果两个都没有id号或者都没有实体类型,看引用相等否
            if ((thisId == null && otherId == null) || (EntityType == null && go.EntityType == null))
            {
                return base.Equals(obj);
            }
            //如果其中有一个id或者实体类型为空,一定不相等
            if (thisId == null || otherId == null || EntityType == null || go.EntityType == null)
            {
                return false;
            }
            //看Id以及实体类型是否相等
            bool result = thisId.ToString().Equals(otherId.ToString()) && this.EntityType.Equals(go.EntityType);
            return result;
        }
        #endregion