/// <summary> /// Compare two objects that implement IList /// </summary> public override void CompareType(CompareParms parms) { //This should never happen, null check happens one level up if (parms.Object1 == null || parms.Object2 == null) { return; } try { parms.Result.AddParent(parms.Object1); parms.Result.AddParent(parms.Object2); Type t1 = parms.Object1.GetType(); Type t2 = parms.Object2.GetType(); //Check if the class type should be excluded based on the configuration if (ExcludeLogic.ShouldExcludeClass(parms.Config, t1, t2)) { return; } parms.Object1Type = t1; parms.Object2Type = t2; if (parms.Result.ExceededDifferences) { return; } bool countsDifferent = ListsHaveDifferentCounts(parms); // If items is collections, need to use default compare logic, not ignore order logic. // We cannot ignore order for nested collections because we will get an reflection exception. // May be need to display some warning or write about this behavior in documentation. if (parms.Config.IgnoreCollectionOrder && !ChildShouldBeComparedWithoutOrder(parms)) { // TODO: allow IndexerComparer to works with types (now it works only with properties). IgnoreOrderLogic ignoreOrderLogic = new IgnoreOrderLogic(RootComparer); ignoreOrderLogic.CompareEnumeratorIgnoreOrder(parms, countsDifferent); } else { CompareItems(parms); } //Properties on the root of a collection CompareProperties(parms); CompareFields(parms); } finally { parms.Result.RemoveParent(parms.Object1); parms.Result.RemoveParent(parms.Object2); } }
/// <summary> /// Compare two objects that implement IList /// </summary> public override void CompareType(CompareParms parms) { //This should never happen, null check happens one level up if (parms.Object1 == null || parms.Object2 == null) { return; } try { parms.Result.AddParent(parms.Object1.GetHashCode()); parms.Result.AddParent(parms.Object2.GetHashCode()); Type t1 = parms.Object1.GetType(); Type t2 = parms.Object2.GetType(); //Check if the class type should be excluded based on the configuration if (ExcludeLogic.ShouldExcludeClass(parms.Config, t1, t2)) { return; } parms.Object1Type = t1; parms.Object2Type = t2; if (parms.Result.ExceededDifferences) { return; } bool countsDifferent = ListsHaveDifferentCounts(parms); if (parms.Config.IgnoreCollectionOrder && !ChildIsListOrDictionary(parms)) { IgnoreOrderLogic ignoreOrderLogic = new IgnoreOrderLogic(RootComparer); ignoreOrderLogic.CompareEnumeratorIgnoreOrder(parms, countsDifferent); } else { CompareItems(parms); } //Properties on the root of a collection CompareProperties(parms); CompareFields(parms); } finally { parms.Result.RemoveParent(parms.Object1.GetHashCode()); parms.Result.RemoveParent(parms.Object2.GetHashCode()); } }
/// <summary> /// Compare two classes /// </summary> public override void CompareType(CompareParms parms) { try { parms.Result.AddParent(parms.Object1); parms.Result.AddParent(parms.Object2); //Custom classes that implement IEnumerable may have the same hash code //Ignore objects with the same hash code if (!(parms.Object1 is IEnumerable) && ReferenceEquals(parms.Object1, parms.Object2)) { return; } Type t1 = parms.Object1.GetType(); Type t2 = parms.Object2.GetType(); //Check if the class type should be excluded based on the configuration if (ExcludeLogic.ShouldExcludeClass(parms.Config, t1, t2)) { return; } parms.Object1Type = t1; parms.Object2Type = t2; //Compare the properties if (parms.Config.CompareProperties) { _propertyComparer.PerformCompareProperties(parms); } //Compare the fields if (parms.Config.CompareFields) { _fieldComparer.PerformCompareFields(parms); } } finally { parms.Result.RemoveParent(parms.Object1); parms.Result.RemoveParent(parms.Object2); } }
public override void CompareType(CompareParms parms) { Type t1 = parms.Object1.GetType(); Type t2 = parms.Object2.GetType(); //Check if the class type should be excluded based on the configuration if (ExcludeLogic.ShouldExcludeClass(parms.Config, t1, t2)) { return; } parms.Object1Type = t1; parms.Object2Type = t2; if (!parms.Config.IgnoreCollectionOrder) { CompareItems(parms); } }
/// <summary> /// Compare two collections. /// </summary> public override void CompareType(CompareParms parms) { try { parms.Result.AddParent(parms.Object1); parms.Result.AddParent(parms.Object2); Type t1 = parms.Object1.GetType(); Type t2 = parms.Object2.GetType(); //Check if the class type should be excluded based on the configuration if (ExcludeLogic.ShouldExcludeClass(parms.Config, t1, t2)) { return; } parms.Object1Type = t1; parms.Object2Type = t2; bool countsDifferent = CollectionsDifferentCount(parms); if (parms.Result.ExceededDifferences) { return; } if (parms.Config.IgnoreCollectionOrder) { IgnoreOrderLogic logic = new IgnoreOrderLogic(RootComparer); logic.CompareEnumeratorIgnoreOrder(parms, countsDifferent); } else { CompareItems(parms); } } finally { parms.Result.RemoveParent(parms.Object1); parms.Result.RemoveParent(parms.Object2); } }