Beispiel #1
0
        // <summary>
        // Compare the value for of a property of LogicalTreeNode.
        // If the value are not of the same type, return false.
        // if the value can be convert to string and the result is not
        // the same just return false.
        // For logical tree nodes, call CompareLogicalTree to compare recursively.
        // Otherwise, use CompareAsGenericObject
        // to compare
        // </summary>
        // <param name="obj1">The first value</param>
        // <param name="obj2">The second value</param>
        // <returns>
        // true, if value is regarded as the same
        // false, otherwise use CompareAsGenericObject to compare
        // </returns>
        private static bool CompareObjects(object obj1, object obj2)
        {
            bool same = false;

            //Both are null
            if (null == obj1 && null == obj2)
            {
                return(true);
            }

            //Only one of them is null
            if (null == obj1)
            {
                TreeComparer.SendCompareMessage("Values is different: 'null' vs. '" + obj2.ToString() + "'.");
                TreeComparer.Break();
                return(false);
            }

            if (null == obj2)
            {
                TreeComparer.SendCompareMessage("Values are different: '" + obj1.ToString() + "' vs. 'null'.");
                TreeComparer.Break();
                return(false);
            }

            //Compare Type
            Type type1 = obj1.GetType();
            Type type2 = obj2.GetType();

            if (!type1.Equals(type2))
            {
                TreeComparer.SendCompareMessage("Type of value is different: '" + type1.FullName + "' vs. '" + type2.FullName + "'.");
                TreeComparer.Break();
                return(false);
            }


            if (type1.IsPrimitive)
            {
                same = TreeComparer.ComparePrimitive(obj1, obj2);
                return(same);
            }

            if (TreeComparer._objectsInTree[0].Contains(obj1.GetHashCode()) || TreeComparer._objectsInTree[1].Contains(obj2.GetHashCode()))
            {
                return(true);
            }

            TreeComparer._objectsInTree[0].Add(obj1.GetHashCode());
            TreeComparer._objectsInTree[1].Add(obj2.GetHashCode());

            return(TreeComparer.CompareGenericObject(obj1, obj2));;
        }