private IEqualityComparer GetPropertyComparerFor(PropertyReference lhs, PropertyReference rhs) { if (lhs.IsCollectionType) { Type lhsElementType = lhs.GetCollectionElementType(); Type rhsElementType = rhs.GetCollectionElementType(); //The only reason GetCollectionElementType would return null is if the collection is empty; //if the collection is empty there will be nothing to compare, hence why its ok to create //a collection comparer that returns true for any element in the collection return(lhsElementType == null && rhsElementType == null ? new CollectionComparer((o1, o2) => true) : new CollectionComparer(GetPropertyComparerFor(lhsElementType ?? rhsElementType))); } else { return(GetPropertyComparerFor(lhs.Type)); } }