UnifiedDiffFile Class

The changes of one file in a unified diff: a --- line, a +++ line and the hunks that follow.

public sealed class UnifiedDiffFile

Properties

NameDescription
HunksGets the hunks, in order. It is empty when the two texts are equal.
NewFileNameGets the name written after +++, without the timestamp that may follow a tab.
OldFileNameGets the name written after ---, without the timestamp that may follow a tab.

Gets the hunks, in order. It is empty when the two texts are equal.

public IReadOnlyList<UnifiedDiffHunk> Hunks { get; }

Gets the name written after +++, without the timestamp that may follow a tab.

public string NewFileName { get; }

Property value

string

Gets the name written after ---, without the timestamp that may follow a tab.

public string OldFileName { get; }

Property value

string

Methods

NameDescription
Apply(string)Applies the hunks to text, the old text, and returns the new text.
ToString()Returns the file in the unified format: the --- and +++ lines followed by the hunks, or an empty string when there is no hunk, as diff -u writes nothing for equal texts.

Apply(string)

UnifiedDiffFile.cs

Applies the hunks to text, the old text, and returns the new text.

public string Apply(string text)

Parameters

text string
The text to patch.

Returns

string The patched text.

Exceptions

ArgumentNullException
text is null.
UnifiedDiffApplyException
A hunk does not match the text.

Remarks

The context and deleted lines of each hunk must match the text exactly. When a hunk does not match at the line its header gives, it is applied at the closest line where it matches, after the previous hunk, as patch does when lines were added or removed elsewhere in the text. The lines of the text are separated by "\n" only.

Returns the file in the unified format: the --- and +++ lines followed by the hunks, or an empty string when there is no hunk, as diff -u writes nothing for equal texts.

public override string ToString()

Returns

string