比较两个对象是否相等

        /// <summary>
        /// 比较两个对象是否相等
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="obj2"></param>
        /// <returns></returns>
        public static bool ObjectEquals(object obj1,object obj2)
        {
            bool bFlag = false;
            string strSerObj1 = SerializeToString(obj1);
            string strSerObj2 = SerializeToString(obj2);
            bFlag = string.Equals(strSerObj1, strSerObj2, StringComparison.OrdinalIgnoreCase);
            return bFlag;
        }
       /// <summary>
        /// 进行序列化
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string SerializeToString(object obj)
        {
            string rtnStr = string.Empty;
            try
            {
                rtnStr = JsonConvert.SerializeObject(obj);
            }
            catch (Exception ex)
            {
                //LogHelper.Error(ex);
                rtnStr = string.Empty;
            }
            return rtnStr;
        }

 

posted @ 2020-08-05 10:09  努力吧兄Dei  阅读(148)  评论(0编辑  收藏  举报