UnifiedDiffFile Class
The changes of one file in a unified diff: a --- line, a +++ line and the hunks that follow.
public sealed class UnifiedDiffFileProperties
| Name | Description |
|---|---|
| Hunks | Gets the hunks, in order. It is empty when the two texts are equal. |
| NewFileName | Gets the name written after +++, without the timestamp that may follow a tab. |
| OldFileName | Gets the name written after ---, without the timestamp that may follow a tab. |
Hunks
UnifiedDiffFile.csGets the hunks, in order. It is empty when the two texts are equal.
public IReadOnlyList<UnifiedDiffHunk> Hunks { get; }Property value
NewFileName
UnifiedDiffFile.csOldFileName
UnifiedDiffFile.csMethods
| Name | Description |
|---|---|
| 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.csApplies the hunks to text, the old text, and returns the new text.
Parameters
textstring- The text to patch.
Returns
string The patched text.
Exceptions
ArgumentNullExceptiontextisnull.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.