private bool IgnoreTypeForType(Type type, Type typeToIgnore) { if (TypeSpecificCompareOptions.ContainsKey(type)) { return(TypeSpecificCompareOptions[type].TypesToIgnore.Contains(typeToIgnore)); } return(TypesToIgnore.Contains(typeToIgnore)); }
private void CompareWithCustomComparer(object object1, object object2, string breadCrumb, Type t1, Delegate customComparer) { if (TypesToIgnore.Contains(t1)) { return; } CustomComparerDelegateWithDifferenceRecording customComparerDelegateWithDifferenceRecording = customComparer as CustomComparerDelegateWithDifferenceRecording; CustomComparerDelegate customComparerDelegate = customComparer as CustomComparerDelegate; if (customComparerDelegateWithDifferenceRecording != null) { // Compare with a custom comparator List <string> differences = customComparerDelegateWithDifferenceRecording.Invoke(object1, object2); if (differences.Count > 0) { Differences.AddRange(differences); } } else { if (customComparerDelegate != null) { // Compare with a custom comparator if (!customComparerDelegate.Invoke(object1, object2)) { Differences.Add(string.Format("object1{0} != object2{0} ({1},{2})", breadCrumb, object1, object2)); } } else { throw new InvalidOperationException("Bad custom comparer specified."); } } if (Differences.Count >= MaxDifferences) { return; } }
private bool ShouldCreateUiFor(Type type, string memberName) { if (TypesToIgnore.Contains(type)) { return(false); } if (MembersToIgnore.Contains(memberName)) { return(false); } if (typeof(Delegate).IsAssignableFrom(type)) { return(false); } return(true); }
/// <summary> /// Compare the properties, fields of a class /// </summary> /// <param name="object1"></param> /// <param name="object2"></param> /// <param name="breadCrumb"></param> private void CompareClass(object object1, object object2, string breadCrumb) { try { _parents.Add(object1); _parents.Add(object2); Type t1 = object1.GetType(); //We ignore the class name if (ElementsToIgnore.Contains(t1.Name)) { return; } if (TypesToIgnore.Contains(t1)) { return; } if (CompareChildrenForType(t1)) { // Compare the properties, if allowed for this object type if (ComparePropertiesForType(t1)) { PerformCompareProperties(t1, object1, object2, breadCrumb); } // Compare the fields, if allowed for this object type if (CompareFieldsForType(t1)) { PerformCompareFields(t1, object1, object2, breadCrumb); } } } finally { _parents.Remove(object1); _parents.Remove(object2); } }