深度比较对象的不同
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+")"); } }