public int CompareTo(object obj) { var other = obj as PartialSnapshotCompression; if (other == null) { return(1); } if (Equals(other)) { return(0); } int result = CompressionType.CompareTo(other.CompressionType); if (result != 0) { return(result); } result = FieldOfVision.CompareTo(other.FieldOfVision); if (result != 0) { return(result); } result = Direction.CompareTo(other.Direction); if (result != 0) { return(result); } if (ChildNodes.Any()) { var sortedNodes = new List <IPartialSnapshotCompressionNode>(); var otherSortedNodes = new List <IPartialSnapshotCompressionNode>(); sortedNodes.AddRange(ChildNodes); otherSortedNodes.AddRange(other.ChildNodes); sortedNodes.Sort(); otherSortedNodes.Sort(); for (int i = 0; i < sortedNodes.Count; i++) { if (otherSortedNodes.Count <= i) { return(-1); } if (!sortedNodes[i].Equals(otherSortedNodes[i])) { return(sortedNodes[i].CompareTo(otherSortedNodes[i])); } } } return(ChildNodes.Count.CompareTo(other.ChildNodes.Count)); }