private static ObjectComparisonMismatch CompareNodes(GraphNode leftNode, GraphNode rightNode) { // check if one of the nodes is null while the other is not if ((leftNode.ObjectValue == null && rightNode.ObjectValue != null) || (leftNode.ObjectValue != null && rightNode.ObjectValue == null)) { var mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectValuesDoNotMatch); return(mismatch); } if (leftNode.ObjectValue != null && rightNode.ObjectValue != null) { // compare type names // if (!leftNode.ObjectType.Equals(rightNode.ObjectType)) { var mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectTypesDoNotMatch); return(mismatch); } // compare primitives, strings, datatimes, guids if (leftNode.ObjectType.IsPrimitive || leftNode.ObjectType == typeof(string) || leftNode.ObjectType == typeof(DateTime) || leftNode.ObjectType == typeof(Guid)) { if (!leftNode.ObjectValue.Equals(rightNode.ObjectValue)) { var mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectValuesDoNotMatch); return(mismatch); } else { return(null); } } } // compare the child count if (leftNode.Children.Count != rightNode.Children.Count) { var type = leftNode.Children.Count > rightNode.Children.Count ? ObjectComparisonMismatchType.RightNodeHasFewerChildren : ObjectComparisonMismatchType.LeftNodeHasFewerChildren; var mismatch = new ObjectComparisonMismatch( leftNode, rightNode, type); return(mismatch); } // No mismatch // return(null); }
private static ObjectComparisonMismatch CompareNodes(GraphNode leftNode, GraphNode rightNode) { // Check if both are null if (leftNode.ObjectValue == null && rightNode.ObjectValue == null) { return(null); } // check if one of them is null if (leftNode.ObjectValue == null || rightNode.ObjectValue == null) { ObjectComparisonMismatch mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectValuesDoNotMatch); return(mismatch); } // compare type names // if (!leftNode.ObjectType.Equals(rightNode.ObjectType)) { ObjectComparisonMismatch mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectTypesDoNotMatch); return(mismatch); } // compare primitives, strings if (leftNode.ObjectType.IsPrimitive || leftNode.ObjectType == typeof(string)) { if (!leftNode.ObjectValue.Equals(rightNode.ObjectValue)) { ObjectComparisonMismatch mismatch = new ObjectComparisonMismatch( leftNode, rightNode, ObjectComparisonMismatchType.ObjectValuesDoNotMatch); return(mismatch); } else { return(null); } } // compare the child count if (leftNode.Children.Count != rightNode.Children.Count) { var type = leftNode.Children.Count > rightNode.Children.Count ? ObjectComparisonMismatchType.RightNodeHasFewerChildren : ObjectComparisonMismatchType.LeftNodeHasFewerChildren; ObjectComparisonMismatch mismatch = new ObjectComparisonMismatch( leftNode, rightNode, type); return(mismatch); } // No mismatch // return(null); }