Exemplo n.º 1
0
        public static YamlNode Diff(this YamlNode node, YamlNode otherNode)
        {
            if (otherNode == null || node.NodeType != otherNode.NodeType || node.GetHashCode() == otherNode.GetHashCode())
            {
                return(null);
            }
            YamlNode result = null;

            switch (node.NodeType)
            {
            case YamlNodeType.Mapping:
                foreach (var keyValuePair in GetMappingChildrenDiff(((YamlMappingNode)node).Children,
                                                                    ((YamlMappingNode)otherNode).Children).Concat(
                             GetMappingChildrenDiff(((YamlMappingNode)otherNode).Children.
                                                    Where(kv => !((YamlMappingNode)node).Children.ContainsKey(kv.Key)),
                                                    ((YamlMappingNode)node).Children)))
                {
                    if (result == null)
                    {
                        result = new YamlMappingNode();
                    }
                    ((YamlMappingNode)result).Children.Add(keyValuePair);
                }
                break;

            case YamlNodeType.Scalar:
            case YamlNodeType.Sequence:
                result = otherNode.Clone();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(result);
        }