Example #1
0
        /// <summary>
        ///     Compares the specified results.
        /// </summary>
        /// <param name="results">The results.</param>
        /// <param name="originalElement">The original element.</param>
        /// <param name="finalElement">The final element.</param>
        private void Compare(ChangeList results, ObjectGraphCapture.ReferenceElement originalElement, ObjectGraphCapture.ReferenceElement finalElement)
        {
            bool areEqual = ReferenceEquals(originalElement.Value, finalElement.Value);

            if (!areEqual)
            {
                var diff = new ReferenceGraphChange
                {
                    Path         = originalElement.Path,
                    DeclaredType = originalElement.DeclaredType
                };
                results.Add(diff);
            }
        }
Example #2
0
        /// <summary>
        ///     Arrays the compare.
        /// </summary>
        /// <param name="retVal">The ret value.</param>
        /// <param name="originalElement">The original element.</param>
        /// <param name="finalElement">The final element.</param>
        private void ArrayCompare(ChangeList retVal, ObjectGraphCapture.ReferenceElement originalElement, ObjectGraphCapture.ReferenceElement finalElement)
        {
            Compare(retVal, originalElement, finalElement);
            var originalArray = (Array)originalElement.Value;
            var finalArray    = (Array)finalElement.Value;

            if ((originalArray == null) || (finalArray == null))
            {
                return;
            }
            var finalList    = new List <Tuple <object, int> >();
            var originalList = new List <Tuple <object, int> >();

            for (int index = 0; index < Math.Min(originalArray.Length, finalArray.Length); ++index)
            {
                object originalItem = originalArray.GetValue(index);
                object finalItem    = finalArray.GetValue(index);
                if (originalItem != null)
                {
                    if (finalItem != null)
                    {
                        // Both Live!
                        if (!CheckSame(originalItem, finalItem))
                        {
                            originalList.Add(new Tuple <object, int>(originalItem, index));
                            finalList.Add(new Tuple <object, int>(finalItem, index));
                        }
                    }
                    else
                    {
                        //! Original Only
                        originalList.Add(new Tuple <object, int>(originalItem, index));
                    }
                }
                else
                {
                    if (finalItem != null)
                    {
                        // Final Only
                        finalList.Add(new Tuple <object, int>(finalItem, index));
                    }
                }
            }

            var match = new List <Tuple <Tuple <object, int>, Tuple <object, int> > >();

            foreach (Tuple <object, int> originalItem in originalList)
            {
                foreach (Tuple <object, int> finalItem in finalList)
                {
                    if (CheckSame(originalItem.Item1, finalItem.Item1))
                    {
                        match.Add(new Tuple <Tuple <object, int>, Tuple <object, int> >(originalItem, finalItem));
                    }
                }
            }
            foreach (Tuple <Tuple <object, int>, Tuple <object, int> > item in match)
            {
                if (item.Item1.Item2 != item.Item2.Item2)
                {
                    retVal.Add(new MiscGraphChange("ArrayIndewx,{0}=>{1})", item.Item1.Item2 != item.Item2.Item2));
                }
                originalList.Remove(item.Item1);
                finalList.Remove(item.Item2);
            }
            if (originalList.Count > 0)
            {
                foreach (Tuple <object, int> pair in originalList)
                {
                    object item = pair.Item1;
                    retVal.Add(new MiscGraphChange("ArrayRemove,{0}@{1})", (item != null) ? item.GetType().Name : "{null}", IndexOf(originalArray, item)));
                }
            }
            if (finalList.Count > 0)
            {
                foreach (Tuple <object, int> pair in finalList)
                {
                    object item = pair.Item1;
                    retVal.Add(new MiscGraphChange("ArrayAdd,{0}@{1})", (item != null) ? item.GetType().Name : "{null}", IndexOf(finalArray, item)));
                }
            }
        }