public void PerformCompareProperties(CompareParms parms) { var properties = Cache.GetPropertyInfo(parms.Object1Type); foreach (PropertyInfo info1 in properties) { if (info1.CanRead == false) { continue; } if (ExcludeLogic.ShouldExcludeMember(parms.Config, info1)) { continue; } var info2 = info1; var value1 = info1.GetValue(parms.Object1, null); var value2 = info2 != null?info2.GetValue(parms.Object2, null) : null; bool object1IsParent = value1 != null && (value1 == parms.Object1 || parms.Result.Parents.ContainsKey(value1.GetHashCode())); bool object2IsParent = value2 != null && (value2 == parms.Object2 || parms.Result.Parents.ContainsKey(value2.GetHashCode())); //Skip properties where both point to the corresponding parent if ((TypeHelper.IsClass(info1.PropertyType) || TypeHelper.IsInterface(info1.PropertyType)) && (object1IsParent && object2IsParent)) { continue; } var breadCrumb = AddBreadCrumb(parms.Object1Type, parms.BreadCrumb, info1.Name); CompareParms childParms = new CompareParms { Result = parms.Result, Config = parms.Config, ParentObject1 = parms.Object1, ParentObject2 = parms.Object2, Object1 = value1, Object2 = value2, BreadCrumb = breadCrumb }; var differentCount = parms.Result.Differences.Count(); rootComparer.Compare(childParms); var newDifferentCount = parms.Result.Differences.Count(); if (differentCount != newDifferentCount) { GenerateUpdatePropertyList(parms, info1, value1, value2); } } }
private void GenerateAddAndUpdateDifference(ref Type type) { IEnumerator enumerator1 = ((IEnumerable)compareParms.Object1).GetEnumerator(); IEnumerator enumerator2; while (enumerator1.MoveNext()) { if (type == null) { type = enumerator1.Current.GetType(); } if (!TypeHelper.IsClass(type)) { break; } if (!typeof(IObjectWithState).IsAssignableFrom(type)) { break; } matchingSpec = GetMatchingSpec(compareParms.Result, type); var currentObject1 = enumerator1.Current; var object1 = currentObject1 as IObjectWithState; string matchIndex1 = GetMatchIndex(compareParms.Result, matchingSpec, currentObject1); var isMatch = false; enumerator2 = ((IEnumerable)compareParms.Object2).GetEnumerator(); while (enumerator2.MoveNext()) { string matchIndex2 = GetMatchIndex(compareParms.Result, matchingSpec, enumerator2.Current); if (matchIndex1 == matchIndex2) { string breadCrumb = string.Format("{0}[{1}]", compareParms.BreadCrumb, matchIndex1); #region Compare Child var childParms = new CompareParms { Result = compareParms.Result, Config = compareParms.Config, ParentObject1 = currentObject1, ParentObject2 = enumerator2.Current, Object1 = currentObject1, Object2 = enumerator2.Current, BreadCrumb = breadCrumb }; var areEqual = rootComparer.Compare(childParms); if (areEqual == true) { object1.ObjectState = ObjectStateType.Unchanged; } else { object1.ObjectState = ObjectStateType.Modified; //AddUpdateObject(compareParms.Result, type, object1); } #endregion isMatch = true; break; } } if (isMatch == false) { object1.ObjectState = ObjectStateType.Added; //AddNewObject(compareParms.Result, type, object1); } } }