TextDiff Class

Computes the differences between two texts.

public static class TextDiff

Methods

NameDescription
ComputeDiff(string, string, TextDiffOptions?)Computes the differences between oldText and newText.
ComputeHierarchyDiff(string, string, IReadOnlyList<TextChunker>, TextDiffOptions?)Computes the differences between oldText and newText, refining each changed chunk with the next chunker in chunkers.

ComputeDiff(string, string, TextDiffOptions?)

TextDiff.cs

Computes the differences between oldText and newText.

public static TextDiffResult ComputeDiff(string oldText, string newText, TextDiffOptions? options = null)

Parameters

oldText string
The original text.
newText string
The modified text.
options TextDiffOptions?
The chunking and comparison options. Defaults to a line diff using TextDiffAlgorithm.Myers with no option ignored.

Returns

TextDiffResult The chunks of both texts in order, each tagged with what happened to it.

Exceptions

ArgumentNullException
oldText or newText is null.

ComputeHierarchyDiff(string, string, IReadOnlyList<TextChunker>, TextDiffOptions?)

TextDiff.cs

Computes the differences between oldText and newText, refining each changed chunk with the next chunker in chunkers.

public static TextDiffHierarchyResult ComputeHierarchyDiff(string oldText, string newText, IReadOnlyList<TextChunker> chunkers, TextDiffOptions? options = null)

Parameters

oldText string
The original text.
newText string
The modified text.
chunkers IReadOnlyList<TextChunker>
The chunking levels, coarsest first — for example [TextChunker.Lines, TextChunker.Words]. At least two are required; use TextDiff.ComputeDiff for a single level. TextDiffOptions.Chunker is not used by this overload.
options TextDiffOptions?
The comparison options. Defaults to TextDiffAlgorithm.Myers with no option ignored.

Returns

TextDiffHierarchyResult The chunks produced by the first chunker, each of which may carry a finer diff of its own.

Exceptions

ArgumentNullException
oldText, newText or chunkers is null.
ArgumentException
chunkers holds fewer than two chunkers, or one of them is null.