DiffPlex is Netstandard 2.0+ C# library to generate textual diffs.
DiffPlex is Netstandard 2.0+ C# library to generate textual diffs.
DiffPlex is C# library to generate textual diffs. It targets netstandard1.0+.
The DiffPlex library currently exposes several interfaces and classes for generating diffs:
IDiffer (implemented by the Differ class) - This is the core diffing class. It exposes the low level functions to generate differences between texts.ISidebySideDiffer (implemented by the SideBySideDiffer class) - This is a higher level interface. It consumes the IDiffer interface and generates a SideBySideDiffModel. This is a model which is suited for displaying the differences of two pieces of text in a side by side view.IThreeWayDiffer (implemented by the ThreeWayDiffer class) - This interface provides three-way diff and merge functionality, enabling intelligent merging by comparing a base text with two modified versions to detect changes and conflicts.UnidiffRenderer - A renderer class that generates unified diff (unidiff) format output compatible with Git, patch utilities, and other standard diff tools.For examples of how to use the API please see the the following projects contained in the DiffPlex solution.
For use of the IDiffer interface see:
SidebySideDiffer.cs contained in the DiffPlex Project.UnidiffFormater.cs contained in the DiffPlex.ConsoleRunner project.For use of the ISidebySideDiffer interface see:
DiffController.cs and associated MVC views in the WebDiffer projectTextBoxDiffRenderer.cs in the SilverlightDiffer projectFor use of the UnidiffRenderer class see:
Program.cs in the DiffPlex.ConsoleRunner project……public interface IChunker
{
///
/// Dive text into sub-parts
///
string[] Chunk(string text);
}Currently provided implementations:
CharacterChunkerCustomFunctionChunkerDelimiterChunkerLineChunkerLineEndingsPreservingChunkerWordChunkerThe UnidiffRenderer class provides functionality to generate unified diff (unidiff) format output, which is the standard format used by Git, patch utilities, and other diff tools.
// Static method for simple usage
string unidiff = UnidiffRenderer.GenerateUnidiff(
oldText: "old content",
newText: "new content",
oldFileName: "file1.txt",
newFileName: "file2.txt"
);
// Instance usage with custom settings
var renderer = new UnidiffRenderer(contextLines: 5);
string unidiff = renderer.Generate(oldText, newText, "before.txt", "after.txt");Key features:
Example output:
--- before.txt
+++ after.txt
@@ -1,4 +1,4 @@
Line 1
-Old line 2
+New line 2
Line 3
Line 4The IThreeWayDiffer interface provides functionality for three-way diffing and merging, which is essential for merge operations in version control systems or when comparing three versions of text.
…Three-way diffing compares three versions of text:
This enables intelligent merging by identifying:
…///
/// Provides methods that generate differences between texts for displaying in a side by side view.
///
public interface ISideBySideDiffBuilder
{
///
/// Builds a diff model for displaying diffs in a side by side view
///
/// The old text.
/// The new text.
/// The side by side diff model
SideBySideDiffModel BuildDiffModel(string oldText, string newText);
}DiffPlex also contains a sample website that shows how to create a basic side by side diff in an ASP MVC website.
DiffPlex includes a Blazor sample application demonstrating how to render textual diffs in modern Blazor applications. The sample showcases both server-side and client-side rendering capabilities with interactive diff visualization.
The Blazor components provide:
To run the sample Blazor application:
cd DiffPlex.Blazor
dotnet runThere are 2 libraries for Windows app development. One is for Windows App SDK, another is for WPF and WinForms.
DiffPlex WinUI library DiffPlex.Windows is used to render textual diffs in your app which targets to Windows App SDK.
using DiffPlex.UI;And insert following code into the root node of your xaml file, e.g. user control, page or window.
xmlns:diffplex="using:DiffPlex.UI"DiffTextView Textual diffs view element.For example.
DiffView.SetText(OldText, NewText);You can also customize the style. Following are some of the properties you can get or set.
…DiffPlex WPF control library DiffPlex.Wpf is used to render textual diffs in your WPF application.
It targets .NET 9, .NET 8, .NET 6, .NET Framework 4.8 and .NET Framework 4.6.
using DiffPlex.Wpf.Controls;To import the controls into your window/page/control, please insert following attribute into the root node (such as ``) of your xaml files.
xmlns:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf"DiffViewer Textual diffs viewer control with view mode switching by setting an old text and a new text to diff.SideBySideDiffViewer Side-by-side (splitted) textual diffs viewer control by setting a diff model SideBySideDiffModel.InlineDiffViewer Inline textual diffs viewer control by setting a diff model DiffPaneModel.For example.
DiffView.OldText = oldText;
DiffView.NewText = newText;You can also customize the style. Following are some of the properties you can get or set.
…And you can listen following event handlers.
// Occurs when the grid splitter loses mouse capture.
public event DragCompletedEventHandler SplitterDragCompleted;
// Occurs one or more times as the mouse changes position when the grid splitter has logical focus and mouse capture.
public event DragDeltaEventHandler SplitterDragDelta;
// Occurs when the grid splitter receives logical focus and mouse capture.
public event DragStartedEventHandler SplitterDragStarted;
// Occurs when the view mode is changed.
public event EventHandler ViewModeChanged;Windows Forms control of diff viewer is a WPF element host control.
It is also included in DiffPlex.Wpf assembly.
You can import it to use in your Windows Forms application.
It targets .NET 8, .NET 6, .NET Framework 4.8 and .NET Framework 4.6.
using DiffPlex.WindowsForms.Controls;Then you can add the following control in window or user control.
DiffViewer Textual diffs viewer control with view mode switching by setting an old text and a new text to diff.For example.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var diffView = new DiffViewer
{
Margin = new Padding(0),
Dock = DockStyle.Fill,
OldText = oldText,
NewText = newText
};
Controls.Add(diffView);
}
}You can also customize the style. Following are some of the properties you can get or set.
…No open issues yet, or sync has not completed.