/// <summary>
        /// Finds all the common elements in all the loaded collections and returns a list. Might want to override if the
        /// diff produces diff elements of a different type
        /// </summary>
        /// <returns>The collection of common elements</returns>
        public virtual IDiffObjectsCollection FindCommonElements()
        {
            int n = _collections.Count;

            IDiffObjectsCollection commonElements = _collections[0];

            for (int i = 1; i < n; i++)
            {
                //disable merges for this diff

                bool allowMerges = _properties.AllowMerges;
                _properties.AllowMerges = false;

                DoDiff(commonElements, _collections[i]);

                _properties.AllowMerges = allowMerges;

                //replace the current collection with the common elements collection
                //at the next iteration the next element in the collection will be compared against the common elements
                commonElements = _collections[i].CommonElements;

                if (commonElements.Count == 0)
                {
                    return(commonElements);                    //return an empty collection, there are no common elements
                }

                //sort the elements by position
                commonElements.SortByPosition();
            }

            return(commonElements);            //the last element will hold all the common elements
        }
Exemple #2
0
        public void LinesDiff()
        {
            string text1 = "LineLine1.1\r\n" +
                           "eniLLine1.3\r\n" +
                           "ABC1.4";
            string text2 = "LineLine2.1\r\n" +
                           "XYZ2.4\r\n" +
                           "eniLLine2.3";

            LinesDiffer differ = new LinesDiffer();

            DiffResult             result      = differ.DoDiff(text1, text2);
            IDiffObjectsCollection firstDiffs  = result.DifferencesForFirst;
            IDiffObjectsCollection secondDiffs = result.DifferencesForSecond;

            firstDiffs.SortByPosition();
            secondDiffs.SortByPosition();

            Assert.IsTrue(firstDiffs[0].ValueEquals(new LetterDiffObject(0, 0, "1")));
            Assert.IsTrue(secondDiffs[0].ValueEquals(new LetterDiffObject(0, 0, "2")));
            Assert.IsTrue(firstDiffs[1].ValueEquals(new LetterDiffObject(0, 0, "1")));
            Assert.IsTrue(secondDiffs[1].ValueEquals(new LineDiffObject(0, 0, "XYZ2.4")));
            Assert.IsTrue(firstDiffs[2].ValueEquals(new LineDiffObject(0, 0, "ABC1.4")));
            Assert.IsTrue(secondDiffs[2].ValueEquals(new LetterDiffObject(0, 0, "2")));
        }