public void Remove(ShouldBeRemovedHandler shouldBeRemovedHandler) { var filteredSubdifferences = new DifferenceHashList(); foreach (var subdifference in m_subdifferences) { if (shouldBeRemovedHandler(subdifference)) { // Do nothing } else if (subdifference is NodeDifference) { var nodeSubdifference = subdifference as NodeDifference; var nbSubdiffsBefore = nodeSubdifference.Subdifferences.Count; nodeSubdifference.Remove(shouldBeRemovedHandler); if ((nodeSubdifference.Subdifferences.Count > 0) || (nbSubdiffsBefore == 0)) { filteredSubdifferences.Add(subdifference); } } else { filteredSubdifferences.Add(subdifference); } } m_subdifferences = filteredSubdifferences; }