TextMerge Class

Merges two texts that were both changed from a common base, as diff3 and git merge do.

public static class TextMerge

Methods

NameDescription
Merge(string, string, string, TextMergeOptions?, CancellationToken)Merges the changes made to baseText in oursText and in theirsText.

Merge(string, string, string, TextMergeOptions?, CancellationToken)

TextMerge.cs

Merges the changes made to baseText in oursText and in theirsText.

public static TextMergeResult Merge(string baseText, string oursText, string theirsText, TextMergeOptions? options = null, CancellationToken cancellationToken = default)

Parameters

baseText string
The common ancestor of both texts.
oursText string
The first changed version.
theirsText string
The second changed version.
options TextMergeOptions?
The diff options, and how to write the conflicts.
cancellationToken CancellationToken
The token to monitor for cancellation requests.

Returns

TextMergeResult The regions of the merge and the merged text.

Exceptions

ArgumentNullException
baseText, oursText or theirsText is null.
ArgumentOutOfRangeException
An option of options is out of range.
OperationCanceledException
cancellationToken is canceled.

Remarks

Both versions are compared to the base. A region changed in only one of them takes that change; a region changed the same way in both takes it once; a region changed differently in both is a conflict. Changes that touch the same place, such as two insertions after the same line, are a conflict even when they do not overlap.