深度比较对象的不同

 StringBuilder content = new StringBuilder();
                var beforeMembers = BeforeDTO.GetType().GetProperties();
                var afterMembers = AfterDTO.GetType().GetProperties();
                for (int i = 0; i < beforeMembers.Length; i++)
                {
                    var beforeVal = beforeMembers[i].GetValue(BeforeDTO, null);
                    var afterVal = afterMembers[i].GetValue(AfterDTO, null);
                    var beforeValue = beforeVal == null ? null : beforeVal.ToString();
                    var afterValue = afterVal == null ? null : afterVal.ToString();
                    if (beforeValue != afterValue)
                    {
                        b = true;
                        content.Append(beforeMembers[i].Name+"("+ beforeValue+"->"+afterValue+")");
                    }
                }

 

posted @ 2021-07-28 09:55  海龟123  阅读(42)  评论(0编辑  收藏  举报