Exemplo n.º 1
0
        private static DeepCompareResult DeepCompare(this object left, IDictionary <string, KeyValuePair <string, object> > rightLeaves)
        {
            // optimization removed: it doenst fill the 'EqualValues' list
            // if (ReferenceEquals(left, right))
            //     return new DeepCompareResult();

            var leftLeafEnumerator = left.Flatten().GetEnumerator();
            var compareResult      = new DeepCompareResult();

            foreach (var leftLeaf in left.Flatten())
            {
                if (rightLeaves.TryGetValue(leftLeaf.Key, out var rightLeaf))
                {
                    DeepCompareLeaves(leftLeaf, rightLeaf, compareResult);
                    rightLeaves.Remove(leftLeaf.Key);
                }
                else
                {
                    compareResult.Missing.Right.Add(leftLeaf.Key);
                }
            }

            // add all uncompared left proerties to the result object
            return(rightLeaves.Aggregate(compareResult, (cr, kv) =>
            {
                cr.Missing.Left.Add(kv.Key);
                return cr;
            }));
        }
Exemplo n.º 2
0
        private static void DeepCompareLeaves(KeyValuePair <string, object> leftLeaf, KeyValuePair <string, object> rightLeaf, DeepCompareResult compareResult)
        {
            if (!EqualityComparer <Type> .Default.Equals(GetTypeOfValueSafe(leftLeaf.Value), GetTypeOfValueSafe(rightLeaf.Value)))
            {
                compareResult.Different.Types.Add(leftLeaf.Key);
            }

            if (!EqualityComparer <object> .Default.Equals(leftLeaf.Value, rightLeaf.Value))
            {
                compareResult.Different.Values.Add(leftLeaf.Key);
            }

            compareResult.EqualValues.Add(leftLeaf.Key);
        }