Diff : Algorithm.Diff Namespace
Merge

A set of diffs all based on a common original document.

public class Merge : IEnumerable


Remarks

Use this class to merge multiple Algorithm.Diff.Diff or Algorithm.Diff.Patch objects, all of which created based on the same base document.

The result of the merger is a list of Algorithm.Diff.Merge+Hunk objects, each of which represents a segment of the original document. A hunk can represent a range in the original document in which no changes were made in any of the revisions, or a range in which one or more of the revised documents had changes.

The hunks are accessed through a for-each over the Merge object.

C# Example
Merge m = new Merge("A few good men.", new string[] { "A few bad men.", "A few good women." }, null);
		
foreach (Merge.Hunk hunk in m) {
    if (hunk.Same) {
        // This region had no changes.
    } else if (!hunk.Conflict) {
        int idx = hunk.ChangedIndex();
        if (hunk.Original().Count == 0) {
            // Something was inserted in the idx'th document
            WriteList(hunk.Range(idx));
        } else if (hunk.Range(idx).Count == 0) {
            // Something was deleted in the idx'th document
            WriteList(hunk.Original());
        } else {
            // The hunk was a normal change
            WriteList(hunk.Original());
            WriteList(hunk.Range(idx));
        }
    } else {
        // There was a conflict.
    }
  
Members

See Also: Inherited members from object.

Constructors
Performs a merge of the provided diffs. The base document must be the left list in each diff.
Computes how to merge the changes between an original document and a collection of revised versions using the object.
Computes how to merge the changes between an original document and a collection of revised versions.
Methods
static MergeLists (IList, IList[], IComparer, IHashCodeProvider) : IList
Returns a new document that is the merger of the changes from the set of revised documents over the original.
Member Details
Merge Constructor
public Merge (IList original, IList[] changed, IComparer comparer, IHashCodeProvider hashcoder)

Computes how to merge the changes between an original document and a collection of revised versions.

Parameters
original
The original document. For instance, an array of strings representing the lines of a file.
changed
An array of revised documents.
comparer
Null to use the objects' own System.Object.Equals method to determine equality among objects in the lists, or a IComparer object to use to perform equality tests.
hashcoder
Null to use the objects' own System.Object.GetHashCode method to determine hash codes for the objects in the lists, or a IHashCodeProvider object to use to provide the hash codes.
Remarks
This constructor first performs diffs between the original document and each of the revised versions. For more information on how the diff is computed, and about how to use the comparer and hashcoder parameters, see Algorithm.Diff.Diff(System.Collections.IList,System.Collections.IList,System.Collections.IComparer,System.Collections.IHashCodeProvider).

MergeLists
public static IList MergeLists (IList original, IList[] changed, IComparer comparer, IHashCodeProvider hashcoder)

Returns a new document that is the merger of the changes from the set of revised documents over the original.

Parameters
original
The original document.
changed
The set of revised versions.
comparer
An optional comparer.
hashcoder
An optional hash code provider.
Returns
The merged document. Each element of the returned list is either an element from the original document, an element from one of the revised documents, or a Algorithm.Diff.Merge+Conflict object.
Remarks
For more information on how to use the comparer and hashcoder parameters, see Algorithm.Diff.Diff(System.Collections.IList,System.Collections.IList,System.Collections.IComparer,System.Collections.IHashCodeProvider).

Merge Constructor
public Merge (string original, string[] changed, IComparer comparer)

Computes how to merge the changes between an original document and a collection of revised versions using the object.

Parameters
original
The original document.
changed
An array of changed documents.
comparer
A comparer to use to compare substrings of the documents, or null to have the default string comparer used.
Remarks
None.

Merge Constructor
public Merge (IDiff[] diffs)

Performs a merge of the provided diffs. The base document must be the left list in each diff.

Parameters
diffs
An array of Algorithm.Diff.Diff objects.
Remarks
None.