Exemple #1
0
        // <summary>
        // Compare two object trees. If all the descendant logical nodes
        // are equivalent, return true, otherwise, return false.
        // </summary>
        // <param name="firstTree">The root for the first tree</param>
        // <param name="secondTree">The root for the second tree</param>
        // <remarks>
        // Compares every event and property for each the node.
        // </remarks>
        // <returns>
        // A structure containing result. If the returned variable name is result.
        // result.Result is CompareResult.Equivalent in the case two nodes are equivalent,
        // and CompareResult.Different otherwise.
        // </returns>
        public static TreeComparerResult CompareLogical(
            Object firstTree,
            Object secondTree)
        {
            TreeComparerResult result = TreeComparer.CompareLogical(firstTree, secondTree, TreeComparer._skipPropertiesDefault);

            ObjectGraphComparer.XamlCompareParity(firstTree, secondTree, result.Result);

            return(result);
        }
Exemple #2
0
        // <summary>
        // Compare two object trees. If all the descendant logical nodes
        // are equivalent, return true, otherwise, return false.
        // </summary>
        // <param name="firstTree">The root for the first tree.</param>
        // <param name="secondTree">The root for the second tree.</param>
        // <param name="propertiesToIgnore">Custom list of properties to ignore.</param>
        // <remarks>
        // Compares every event and property for each the node.
        // </remarks>
        // <returns>
        // A structure containing result. If the returned variable name is result.
        // result.Result is CompareResult.Equivalent in the case two nodes are equivalent,
        // and CompareResult.Different otherwise.
        // </returns>
        public static TreeComparerResult CompareLogical(
            Object firstTree,
            Object secondTree,
            Dictionary <string, PropertyToIgnore> propertiesToIgnore)
        {
            if (propertiesToIgnore == null)
            {
                throw new ArgumentNullException("propertiesToIgnore", "Argument must be a non-null Dictionary.");
            }

            TreeComparerResult result = new TreeComparerResult();

            result.Result = CompareResult.Equivalent;

            // Validate parameters, both objects are null
            if (null == firstTree && null == secondTree)
            {
                return(result);
            }

            result.Result = CompareResult.Different;

            // Validate parameters, only one object is null
            if (null == firstTree || null == secondTree)
            {
                return(result);
            }

            // Compare the types
            if (!firstTree.GetType().Equals(secondTree.GetType()))
            {
                TreeComparer.SendCompareMessage("Two nodes have different types: '" + firstTree.GetType().FullName + "' vs. '" + secondTree.GetType().FullName + "'.");
                TreeComparer.Break();
                return(result);
            }

            bool same = false;

            // Create hashtables that will contain objects in the trees.
            // This is used to break loops.
            TreeComparer._objectsInTree[0] = new List <int>();
            TreeComparer._objectsInTree[1] = new List <int>();

            TreeComparer._skipProperties = propertiesToIgnore;

            // Include default skip properties if necessary.
            if (TreeComparer._skipProperties != TreeComparer._skipPropertiesDefault)
            {
                TreeComparer._MergeDictionaries(TreeComparer._skipProperties, TreeComparer._skipPropertiesDefault);
            }

            try
            {
                same = CompareObjects(firstTree, secondTree);
            }
            finally
            {
                _objectsInTree[0] = null;
                _objectsInTree[1] = null;
                _skipProperties   = null;
            }

            // Two trees are equivalent
            if (same)
            {
                result.Result = CompareResult.Equivalent;
            }

            return(result);
        }