### Three-Way Diff and Merge Usage Example Source: https://github.com/mmanela/diffplex/blob/master/README.md Demonstrates how to use the IThreeWayDiffer interface to perform diffs and merges. This example shows instantiation, calling the CreateDiffs and CreateMerge methods, and checking for merge conflicts. ```csharp var threeWayDiffer = new ThreeWayDiffer(); // Three-way diff var diffResult = threeWayDiffer.CreateDiffs(baseText, oldText, newText, ignoreWhiteSpace: false, ignoreCase: false, new LineChunker()); // Three-way merge with automatic conflict detection var mergeResult = threeWayDiffer.CreateMerge(baseText, oldText, newText, ignoreWhiteSpace: false, ignoreCase: false, new LineChunker()); // Check for conflicts if (mergeResult.HasConflicts) { Console.WriteLine($"Found {mergeResult.ConflictBlocks.Count} conflicts"); } else { Console.WriteLine("Merge completed successfully"); Console.WriteLine(mergeResult.MergedText); } ``` -------------------------------- ### Running the Blazor Application Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Blazor/README.md Instructions for running the DiffPlex.Blazor application. Ensure .NET 9.0 or later is installed and use 'dotnet run' in the project directory. ```bash dotnet run ``` -------------------------------- ### Install Jekyll Dependencies Source: https://github.com/mmanela/diffplex/blob/master/WebDiffer/wwwroot/lib/bootstrap/README.md Use this command to install Jekyll and other Ruby dependencies required for running the Bootstrap documentation locally. ```bash bundle install ``` -------------------------------- ### Instantiate DiffViewer Control Source: https://github.com/mmanela/diffplex/blob/master/README.md Example of how to declare a DiffViewer control in XAML. ```xaml ``` -------------------------------- ### Restore DiffPlex Project Packages Source: https://github.com/mmanela/diffplex/blob/master/AGENT.md Ensure all project dependencies are downloaded and installed. ```bash dotnet restore ``` -------------------------------- ### WinUI 3 DiffTextView Setup Source: https://context7.com/mmanela/diffplex/llms.txt Integrate the DiffTextView control in WinUI 3 applications. Set text content and configure display properties like split view, whitespace ignoring, and collapsed unchanged sections. ```csharp // MainWindow.xaml — declare namespace: // xmlns:diffplex="using:DiffPlex.UI" // // // MainWindow.xaml.cs public sealed partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DiffView.SetText( "First line\nSecond line\nThird line\n", "First line\nNew second\nThird line\n"); DiffView.IsSplitView = true; // side-by-side DiffView.IsUnchangedSectionCollapsed = true; DiffView.LineCountForContext = 2; DiffView.IgnoreWhiteSpace = true; } } ``` -------------------------------- ### Serve Bootstrap Documentation Locally Source: https://github.com/mmanela/diffplex/blob/master/WebDiffer/wwwroot/lib/bootstrap/README.md Run this command from the root of the Bootstrap directory to serve the documentation locally. Access it via http://localhost:9001. ```bash bundle exec jekyll serve ``` -------------------------------- ### Run Sample Blazor Application Source: https://github.com/mmanela/diffplex/blob/master/README.md Command to navigate to the DiffPlex Blazor sample application directory and run it. This is used to test or utilize the Blazor components for interactive diff visualization. ```bash cd DiffPlex.Blazor dotnet run ``` -------------------------------- ### Modern C# Collection Initialization Source: https://github.com/mmanela/diffplex/blob/master/AGENT.md Use concise syntax for initializing collections in C#. ```csharp data.Pieces = []; ``` -------------------------------- ### Create and Show DiffTextWindow Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Windows/README.md Instantiate a DiffTextWindow, set its title, activate it, and then populate it with the text to be diffed. ```csharp var window = new DiffTextWindow { Title = windowTitle }; window.Activate(); window.SetText(oldText, newText); ``` -------------------------------- ### Build DiffPlex Project Source: https://github.com/mmanela/diffplex/blob/master/AGENT.md Use this command to build the entire DiffPlex solution. ```bash dotnet build ``` -------------------------------- ### Bootstrap Project Structure Source: https://github.com/mmanela/diffplex/blob/master/WebDiffer/wwwroot/lib/bootstrap/README.md This outlines the typical directory structure of a Bootstrap download, showing the organization of CSS, JavaScript, and font files. ```bash bootstrap/ ├── css/ │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ ├── bootstrap.min.css.map │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ └── bootstrap-theme.min.css.map ├── js/ │ ├── bootstrap.js │ └── bootstrap.min.js └── fonts/ ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2 ``` -------------------------------- ### Initialize DiffViewer Control Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Wpf/README.md Initialize the DiffViewer control in XAML, setting headers for old and new text. ```xaml ``` -------------------------------- ### Create Diffs: Line, Character, Word, and Custom Source: https://context7.com/mmanela/diffplex/llms.txt Use `Differ.CreateDiffs` for various diffing granularities. Specify `IChunker` for custom tokenization. Ensure `Differ.Instance` is used for thread-safety. ```csharp using DiffPlex; using DiffPlex.Chunkers; using DiffPlex.Model; var differ = Differ.Instance; // thread-safe singleton // Line diff DiffResult lineResult = differ.CreateLineDiffs( "alpha\nbeta\ngamma\n", "alpha\nBETA\ndelta\n", ignoreWhitespace: false, ignoreCase: false); Console.WriteLine($"Old pieces: {lineResult.PiecesOld.Count}"); Console.WriteLine($"New pieces: {lineResult.PiecesNew.Count}"); foreach (DiffBlock block in lineResult.DiffBlocks) Console.WriteLine($"Delete {block.DeleteCountA} @ {block.DeleteStartA}, Insert {block.InsertCountB} @ {block.InsertStartB}"); // Character diff DiffResult charResult = differ.CreateCharacterDiffs("abcde", "abXde", ignoreWhitespace: false); // Word diff with custom separators DiffResult wordResult = differ.CreateWordDiffs( "the quick brown fox", "the slow brown fox", ignoreWhitespace: false, separators: new[] { ' ', ',', '.' }); // Fully generic: supply any IChunker DiffResult custom = differ.CreateDiffs( "func_a();func_b();", "func_a();func_c();", ignoreWhiteSpace: false, ignoreCase: false, chunker: new DelimiterChunker(new[] { ';' })); ``` -------------------------------- ### Generate Unidiff Format Output Source: https://github.com/mmanela/diffplex/blob/master/README.md Provides static and instance methods for generating unified diff output. Supports custom file names and configurable context lines. Useful for integrating with Git and patch tools. ```csharp // 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"); ``` -------------------------------- ### Generate Git-Compatible Unidiff Output Source: https://context7.com/mmanela/diffplex/llms.txt Use `UnidiffRenderer` to generate standard unified diff output. The static `GenerateUnidiff` method is quick for basic usage, while the instance `Generate` method allows configuring context line count. ```csharp using DiffPlex.Renderer; string oldText = "line 1\nline 2\nline 3\nline 4\nline 5\n"; string newText = "line 1\nLINE 2\nline 3\nLINE 4\nline 5\n"; // Static helper — quickest usage string patch = UnidiffRenderer.GenerateUnidiff( oldText, newText, oldFileName: "original.txt", newFileName: "modified.txt", ignoreWhitespace: false, ignoreCase: false, contextLines: 1); Console.WriteLine(patch); // --- original.txt // +++ modified.txt // @@ -1,3 +1,3 @@ // line 1 // -line 2 // +LINE 2 // line 3 // @@ -3,3 +3,3 @@ // line 3 // -line 4 // +LINE 4 // line 5 // Instance form with custom context window var renderer = new UnidiffRenderer(contextLines: 5); string widePatch = renderer.Generate(oldText, newText, "old.txt", "new.txt"); // Render from a pre-computed DiffResult var differ = new DiffPlex.Differ(); var diffResult = differ.CreateLineDiffs(oldText, newText, ignoreWhitespace: false); string patchFromResult = renderer.Generate(diffResult, "old.txt", "new.txt"); // Returns empty string when texts are identical string empty = UnidiffRenderer.GenerateUnidiff("same", "same"); // "" ``` -------------------------------- ### Run All Tests in DiffPlex Source: https://github.com/mmanela/diffplex/blob/master/AGENT.md Execute all tests across all projects within the DiffPlex solution. ```bash dotnet test ``` -------------------------------- ### Import DiffPlex UI Namespace Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Windows/README.md Import the DiffPlex UI namespace for use in your C# code. ```csharp using DiffPlex.UI; ``` -------------------------------- ### Initialize InlineDiffViewer Control Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Wpf/README.md Initialize the InlineDiffViewer control in XAML. It requires setting the diff model via code. ```xaml ``` -------------------------------- ### Import DiffPlex WPF Controls Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Wpf/README.md Import the DiffPlex.Wpf.Controls namespace for using the diff viewer controls. ```csharp using DiffPlex.Wpf.Controls; ``` -------------------------------- ### IChunker Implementations Source: https://context7.com/mmanela/diffplex/llms.txt Various implementations of the `IChunker` interface allow for different granularities of text comparison, from lines to individual characters. ```APIDOC ## `IChunker` implementations — Tokenizing text for diffing All chunkers implement `IChunker` (`string[] Chunk(string text)`) and can be passed to any `CreateDiffs` overload. Choosing the right chunker determines the granularity of the diff. ### LineChunker Splits text into lines based on newline characters. ### LineEndingsPreservingChunker Similar to `LineChunker` but preserves line ending characters (`\r\n`). ### WordChunker Splits text into words, typically using whitespace as a delimiter. ### CharacterChunker Splits text into individual characters. ### DelimiterChunker Splits text based on a provided set of delimiter characters. ### CustomFunctionChunker Allows defining a custom splitting function for tokenization. ### Usage Example ```csharp using DiffPlex; using DiffPlex.Chunkers; var differ = Differ.Instance; var result = differ.CreateDiffs( "a,b,c", "a,X,c", ignoreWhiteSpace: false, ignoreCase: false, chunker: new DelimiterChunker(new[] { ',' })); ``` ``` -------------------------------- ### Initialize SideBySideDiffViewer Control Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Wpf/README.md Initialize the SideBySideDiffViewer control in XAML. It requires setting the diff model via code. ```xaml ``` -------------------------------- ### Customize DiffViewer Control Properties Source: https://github.com/mmanela/diffplex/blob/master/README.md Explore and set various properties to customize the appearance and behavior of the DiffViewer control, such as headers, view modes, fonts, and colors. ```csharp // The header of old text. public string OldTextHeader { get; set; } // The header of new text. public string NewTextHeader { get; set; } // true if it is in side-by-side (split) view; // otherwise, false, in inline (unified) view. public bool IsSideBySideViewMode { get; } // true if collapse unchanged sections; otherwise, false. public bool IgnoreUnchanged { get; set; } // The font size. public double FontSize { get; set; } // The preferred font family names in string. public string FontFamilyNames { get; set; } // The font weight. public int FontWeight { get; set; } // The font style. public bool IsFontItalic { get; set; } // The default text color (foreground brush). public Color ForeColor { get; set; } // The background brush of the line inserted. public Color InsertedBackColor { get; set; } // The background brush of the line deleted. public Color DeletedBackColor { get; set; } // The text color (foreground color) of the line number. public Color LineNumberForeColor { get; set; } // The width of the line number and change type symbol. public int LineNumberWidth { get; set; } // The background brush of the line imaginary. public Color ImaginaryBackColor { get; set; } // The text color (foreground color) of the change type symbol. public Color ChangeTypeForeColor { get; set; } // The background brush of the header. public Color HeaderBackColor { get; set; } // The height of the header. public double HeaderHeight { get; set; } // The background brush of the grid splitter. public Color SplitterBackColor { get; set; } // The width of the grid splitter. public Padding SplitterWidth { get; set; } // A value that represents the actual calculated width of the left side panel. public double LeftSideActualWidth { get; } // A value that represents the actual calculated width of the right side panel. public double RightSideActualWidth { get; } ``` -------------------------------- ### Add DiffViewer Control to Form Source: https://github.com/mmanela/diffplex/blob/master/README.md Instantiate and add the DiffViewer control to your form, setting its properties for layout and content. ```csharp 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); } } ``` -------------------------------- ### Import DiffViewer Control Namespace Source: https://github.com/mmanela/diffplex/blob/master/README.md Import the necessary namespace to use the DiffViewer control in your Windows Forms application. ```csharp using DiffPlex.WindowsForms.Controls; ``` -------------------------------- ### Test Specific DiffPlex Project Source: https://github.com/mmanela/diffplex/blob/master/AGENT.md Run tests only for the specified project, e.g., Facts.DiffPlex. ```bash dotnet test Facts.DiffPlex ``` -------------------------------- ### IChunker Implementations for Text Tokenization Source: https://context7.com/mmanela/diffplex/llms.txt Choose an `IChunker` implementation to define how text is tokenized for diffing. The default `LineChunker` splits by lines. Custom chunkers allow for character, word, or delimiter-based tokenization. ```csharp using DiffPlex; using DiffPlex.Chunkers; string text = "Hello, world!\nSecond line.\n"; // Line chunker (default for most builders) string[] lines = new LineChunker().Chunk(text); // → ["Hello, world!\n", "Second line.\n"] // Line endings preserving chunker — keeps \r\n intact string[] linesPreserved = new LineEndingsPreservingChunker().Chunk(text); // Word chunker (splits on whitespace) string[] words = new WordChunker().Chunk("the quick brown fox"); // → ["the", " ", "quick", " ", "brown", " ", "fox"] // Character chunker string[] chars = new CharacterChunker().Chunk("abc"); // → ["a", "b", "c"] // Delimiter chunker — split on any set of chars string[] tokens = new DelimiterChunker(new[] { ',', ' ', '!' }).Chunk("Hello, world!"); // → ["Hello", ",", " ", "world", "!"] // Custom function chunker var csvChunker = new CustomFunctionChunker(s => s.Split(',')); string[] fields = csvChunker.Chunk("a,b,c"); // → ["a", "b", "c"] // Using custom chunker with Differ directly var differ = Differ.Instance; var result = differ.CreateDiffs( "a,b,c", "a,X,c", ignoreWhiteSpace: false, ignoreCase: false, chunker: new DelimiterChunker(new[] { ',' })); ``` -------------------------------- ### IDiffer Interface Methods Source: https://github.com/mmanela/diffplex/blob/master/README.md The IDiffer interface provides methods to generate differences between texts using various comparison strategies. ```APIDOC ## CreateLineDiffs ### Description Generates a diff by comparing text line by line. ### Method `CreateLineDiffs(string oldText, string newText, bool ignoreWhiteSpace)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text. - `newText` (string) - Required - The new text. - `ignoreWhiteSpace` (bool) - Required - If true, ignores white space when determining if lines are the same. ### Returns `DiffResult` - An object detailing the differences. ``` ```APIDOC ## CreateCharacterDiffs ### Description Generates a diff by comparing text character by character. ### Method `CreateCharacterDiffs(string oldText, string newText, bool ignoreWhitespace)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text. - `newText` (string) - Required - The new text. - `ignoreWhitespace` (bool) - Required - If true, treats all whitespace characters as empty strings. ### Returns `DiffResult` - An object detailing the differences. ``` ```APIDOC ## CreateWordDiffs ### Description Generates a diff by comparing text word by word. ### Method `CreateWordDiffs(string oldText, string newText, bool ignoreWhitespace, char[] separators)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text. - `newText` (string) - Required - The new text. - `ignoreWhitespace` (bool) - Required - If true, ignores white space when determining if words are the same. - `separators` (char[]) - Required - The list of characters which define word separators. ### Returns `DiffResult` - An object detailing the differences. ``` ```APIDOC ## CreateCustomDiffs ### Description Generates a diff by comparing text in chunks determined by a supplied chunker function. ### Method `CreateCustomDiffs(string oldText, string newText, bool ignoreWhiteSpace, Func chunker)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text. - `newText` (string) - Required - The new text. - `ignoreWhiteSpace` (bool) - Required - If true, ignores white space when determining if chunks are the same. - `chunker` (Func) - Required - A function that will break the text into chunks. ### Returns `DiffResult` - An object detailing the differences. ``` ```APIDOC ## CreateDiffs ### Description Generates a diff by comparing text line by line with additional options for case sensitivity and custom chunking. ### Method `CreateDiffs(string oldText, string newText, bool ignoreWhiteSpace, bool ignoreCase, IChunker chunker)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text. - `newText` (string) - Required - The new text. - `ignoreWhiteSpace` (bool) - Required - If true, ignores white space when determining if lines are the same. - `ignoreCase` (bool) - Required - Determines if the text comparison is case sensitive or not. - `chunker` (IChunker) - Required - Component responsible for tokenizing the compared texts. ### Returns `DiffResult` - An object detailing the differences. ``` -------------------------------- ### Generate Inline Diffs and Display Changes Source: https://github.com/mmanela/diffplex/blob/master/README.md Use InlineDiffBuilder to compare two texts and iterate through the resulting lines to display insertions, deletions, or unchanged text with appropriate console colors. Ensure to reset the console color afterwards. ```csharp var diff = InlineDiffBuilder.Diff(before, after); var savedColor = Console.ForegroundColor; foreach (var line in diff.Lines) { switch (line.Type) { case ChangeType.Inserted: Console.ForegroundColor = ConsoleColor.Green; Console.Write("+ "); break; case ChangeType.Deleted: Console.ForegroundColor = ConsoleColor.Red; Console.Write("- "); break; default: Console.ForegroundColor = ConsoleColor.Gray; // compromise for dark or light background Console.Write(" "); break; } Console.WriteLine(line.Text); } Console.ForegroundColor = savedColor; ``` -------------------------------- ### Side-by-Side Diff with Word Sub-Diffs Source: https://context7.com/mmanela/diffplex/llms.txt Generates a side-by-side diff view using `SideBySideDiffBuilder.Diff`. This method returns a `SideBySideDiffModel` with two panes and highlights word-level changes within modified lines. Options for ignoring whitespace and case are available. ```csharp using DiffPlex.DiffBuilder; using DiffPlex.DiffBuilder.Model; string oldText = "Hello world\nFoo bar baz\n"; string newText = "Hello DiffPlex\nFoo qux baz\n"; SideBySideDiffModel model = SideBySideDiffBuilder.Diff(oldText, newText, ignoreWhiteSpace: true, ignoreCase: false); for (int i = 0; i < model.OldText.Lines.Count; i++) { DiffPiece oldLine = model.OldText.Lines[i]; DiffPiece newLine = model.NewText.Lines[i]; Console.WriteLine($"OLD [{oldLine.Type,10}] {oldLine.Text}"); Console.WriteLine($"NEW [{newLine.Type,10}] {newLine.Text}"); // Word-level sub-diff for modified lines if (oldLine.Type == ChangeType.Modified) { foreach (var word in oldLine.SubPieces) Console.Write($" old-word [{word.Type}] '{word.Text}'"); Console.WriteLine(); foreach (var word in newLine.SubPieces) Console.Write($" new-word [{word.Type}] '{word.Text}'"); Console.WriteLine(); } } ``` -------------------------------- ### DiffViewer Control Event Handlers Source: https://github.com/mmanela/diffplex/blob/master/README.md Event handlers available for the DiffViewer control to respond to user interactions and state changes. ```csharp // Occurs when the grid splitter loses mouse capture. public event DragCompletedEventHandler SplitterDragCompleted; ``` ```csharp // Occurs one or more times as the mouse changes position when the grid splitter has logical focus and mouse capture. public event DragDeltaEventHandler SplitterDragDelta; ``` ```csharp // Occurs when the grid splitter receives logical focus and mouse capture. public event DragStartedEventHandler SplitterDragStarted; ``` ```csharp // Occurs when the view mode is changed. public event EventHandler ViewModeChanged; ``` -------------------------------- ### Set Text for DiffViewer Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Wpf/README.md Set the OldText and NewText properties of the DiffViewer control in C# to display the differences. ```csharp DiffView.OldText = OldText; DiffView.NewText = NewText; ``` -------------------------------- ### Inline Diff Generation with DiffPlex Source: https://context7.com/mmanela/diffplex/llms.txt Generates a single-pane line-by-line diff using `InlineDiffBuilder.Diff`. This static method is a convenience entry point that uses an internal `Differ` instance. It supports options to ignore whitespace and case. ```csharp using DiffPlex.DiffBuilder; using DiffPlex.DiffBuilder.Model; string oldText = "line one\nline two\nline three\n"; string newText = "line one\nline TWO\nline four\n"; // Static convenience method — ignores whitespace by default DiffPaneModel diff = InlineDiffBuilder.Diff(oldText, newText, ignoreWhiteSpace: true, ignoreCase: false); foreach (DiffPiece line in diff.Lines) { string prefix = line.Type switch { ChangeType.Inserted => "+ ", ChangeType.Deleted => "- ", ChangeType.Modified => "~ ", ChangeType.Unchanged => " ", _ => "? " }; Console.WriteLine($"{prefix}{line.Text} (pos={line.Position})"); } ``` -------------------------------- ### Create Three-Way Diffs Source: https://context7.com/mmanela/diffplex/llms.txt Compares a base text against two modified versions to identify differences. Use when needing to classify changes as unchanged, old-only, new-only, both same, or conflict. ```csharp using DiffPlex; using DiffPlex.Chunkers; using DiffPlex.Model; string baseText = "alpha\nbeta\ngamma\ndelta\n"; string oldText = "alpha\nBETA\ngamma\ndelta\n"; // changed "beta" → "BETA" string newText = "alpha\nbeta\nGAMMA\ndelta\n"; // changed "gamma" → "GAMMA" var differ = ThreeWayDiffer.Instance; ThreeWayDiffResult result = differ.CreateDiffs( baseText, oldText, newText, ignoreWhiteSpace: false, ignoreCase: false, chunker: LineChunker.Instance); Console.WriteLine($"Base lines : {result.PiecesBase.Count}"); Console.WriteLine($"Old lines : {result.PiecesOld.Count}"); Console.WriteLine($"New lines : {result.PiecesNew.Count}"); foreach (var block in result.DiffBlocks) { Console.WriteLine( $"{block.ChangeType,-12} base[{block.BaseStart}+{block.BaseCount}]" + $" old[{block.OldStart}+{block.OldCount}]" + $" new[{block.NewStart}+{block.NewCount}]"); } // OldOnly base[1+1] old[1+1] new[1+1] // NewOnly base[2+1] old[2+1] new[2+1] ``` -------------------------------- ### IThreeWayDiffer Interface Source: https://github.com/mmanela/diffplex/blob/master/README.md Provides functionality for three-way diffing and merging, essential for merge operations in version control systems or when comparing three versions of text. ```APIDOC ## CreateDiffs ### Description Creates a three-way diff by comparing base, old, and new text line by line. ### Method `CreateDiffs` ### Parameters - **baseText** (string) - The base text for comparison. - **oldText** (string) - The old version of the text. - **newText** (string) - The new version of the text. - **ignoreWhiteSpace** (bool) - Whether to ignore whitespace differences. - **ignoreCase** (bool) - Whether to ignore case differences. - **chunker** (IChunker) - An object responsible for chunking the text. ### Returns - **ThreeWayDiffResult** - An object containing the results of the three-way diff. ``` ```APIDOC ## CreateMerge ### Description Creates a three-way merge by comparing base, old, and new text line by line. ### Method `CreateMerge` ### Parameters - **baseText** (string) - The base text for comparison. - **oldText** (string) - The old version of the text. - **newText** (string) - The new version of the text. - **ignoreWhiteSpace** (bool) - Whether to ignore whitespace differences. - **ignoreCase** (bool) - Whether to ignore case differences. - **chunker** (IChunker) - An object responsible for chunking the text. ### Returns - **ThreeWayMergeResult** - An object containing the results of the three-way merge, including merged text and conflict information. ``` -------------------------------- ### Initialize DiffTextView in XAML Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Windows/README.md Declare a DiffTextView element in your XAML, giving it a name for later reference. ```xaml ``` -------------------------------- ### Windows Forms DiffViewer Integration Source: https://context7.com/mmanela/diffplex/llms.txt Embed the WPF DiffViewer control within a Windows Forms application using ElementHost. Configure appearance and behavior properties for the diff view. ```csharp using DiffPlex.WindowsForms.Controls; using System.Windows.Forms; public partial class MainForm : Form { public MainForm() { InitializeComponent(); var diffView = new DiffViewer { Dock = DockStyle.Fill, Margin = new Padding(0), OldText = "version one\nsome content\n", NewText = "version two\nsome content\n", FontSize = 13.0, IgnoreUnchanged = false, InsertedBackColor = System.Drawing.Color.LightGreen, DeletedBackColor = System.Drawing.Color.LightCoral, LineNumberWidth = 50 }; Controls.Add(diffView); } } ``` -------------------------------- ### ISideBySideDiffBuilder Interface Source: https://github.com/mmanela/diffplex/blob/master/README.md Provides methods for generating differences between texts suitable for displaying in a side-by-side view. ```APIDOC ## BuildDiffModel ### Description Builds a diff model for displaying differences between two texts in a side-by-side view. ### Method `BuildDiffModel` ### Parameters - **oldText** (string) - The old version of the text. - **newText** (string) - The new version of the text. ### Returns - **SideBySideDiffModel** - A model containing the differences formatted for side-by-side display. ``` -------------------------------- ### DiffViewer Control Properties Source: https://github.com/mmanela/diffplex/blob/master/README.md Commonly used properties for customizing the appearance and behavior of the DiffViewer control. ```csharp // The header of old text. public string OldTextHeader { get; set; } ``` ```csharp // The header of new text. public string NewTextHeader { get; set; } ``` ```csharp // true if it is in side-by-side (split) view; // otherwise, false, in inline (unified) view. public bool IsSideBySideViewMode { get; } ``` ```csharp // true if collapse unchanged sections; otherwise, false. public bool IgnoreUnchanged { get; set; } ``` ```csharp // Hides the line numbers. public bool HideLineNumbers { get; set; } ``` ```csharp // The font size. public double FontSize { get; set; } ``` ```csharp // The preferred font family. public FontFamily FontFamily { get; set; } ``` ```csharp // The font weight. public FontWeight FontWeight { get; set; } ``` ```csharp // The font style. public FontStyle FontStyle { get; set; } ``` ```csharp // The font-stretching characteristics. public FontStretch FontStretch { get; set; } ``` ```csharp // The default text color (foreground brush). public Brush Foreground { get; set; } ``` ```csharp // The background brush of the line inserted. public Brush InsertedBackground { get; set; } ``` ```csharp // The background brush of the line deleted. public Brush DeletedBackground { get; set; } ``` ```csharp // The text color (foreground brush) of the line number. public Brush LineNumberForeground { get; set; } ``` ```csharp // The width of the line number and change type symbol. public int LineNumberWidth { get; set; } ``` ```csharp // The background brush of the line imaginary. public Brush ImaginaryBackground { get; set; } ``` ```csharp // The text color (foreground brush) of the change type symbol. public Brush ChangeTypeForeground { get; set; } ``` ```csharp // The background brush of the header. public Brush HeaderBackground { get; set; } ``` ```csharp // The height of the header. public double HeaderHeight { get; set; } ``` ```csharp // The background brush of the grid splitter. public Brush SplitterBackground { get; set; } ``` ```csharp // The width of the grid splitter. public Thickness SplitterWidth { get; set; } ``` ```csharp // A value that represents the actual calculated width of the left side panel. public double LeftSideActualWidth { get; } ``` ```csharp // A value that represents the actual calculated width of the right side panel. public double RightSideActualWidth { get; } ``` -------------------------------- ### Set Text for DiffTextView Source: https://github.com/mmanela/diffplex/blob/master/README.md Call this method on your DiffTextView instance to display the differences between two text strings. Ensure OldText and NewText variables are defined. ```csharp DiffView.SetText(OldText, NewText); ``` -------------------------------- ### IDiffer Interface Definition Source: https://github.com/mmanela/diffplex/blob/master/README.md Defines methods for generating text differences at various granularities: line-by-line, character-by-character, word-by-word, and custom chunking. Supports options for ignoring whitespace, case, and custom tokenization. ```csharp /// /// Provides methods for generate differences between texts /// public interface IDiffer { /// /// Create a diff by comparing text line by line /// /// The old text. /// The new text. /// if set to true will ignore white space when determining if lines are the same. /// A DiffResult object which details the differences DiffResult CreateLineDiffs(string oldText, string newText, bool ignoreWhiteSpace); /// /// Create a diff by comparing text character by character /// /// The old text. /// The new text. /// if set to true will treat all whitespace characters are empty strings. /// A DiffResult object which details the differences DiffResult CreateCharacterDiffs(string oldText, string newText, bool ignoreWhitespace); /// /// Create a diff by comparing text word by word /// /// The old text. /// The new text. /// if set to true will ignore white space when determining if words are the same. /// The list of characters which define word separators. /// A DiffResult object which details the differences DiffResult CreateWordDiffs(string oldText, string newText, bool ignoreWhitespace, char[] separators); /// /// Create a diff by comparing text in chunks determined by the supplied chunker function. /// /// The old text. /// The new text. /// if set to true will ignore white space when determining if chunks are the same. /// A function that will break the text into chunks. /// A DiffResult object which details the differences DiffResult CreateCustomDiffs(string oldText, string newText, bool ignoreWhiteSpace, Func chunker); /// /// Create a diff by comparing text line by line /// /// The old text. /// The new text. /// if set to true will ignore white space when determining if lines are the same. /// Determine if the text comparision is case sensitive or not /// Component responsible for tokenizing the compared texts /// A DiffResult object which details the differences DiffResult CreateDiffs(string oldText, string newText, bool ignoreWhiteSpace, bool ignoreCase, IChunker chunker); } ``` -------------------------------- ### UnidiffRenderer Class Source: https://github.com/mmanela/diffplex/blob/master/README.md The UnidiffRenderer class generates unified diff (unidiff) format output, compatible with Git and patch utilities. ```APIDOC ## GenerateUnidiff (Static Method) ### Description Provides a static method for simple usage to generate unified diff format. ### Method `UnidiffRenderer.GenerateUnidiff(string oldText, string newText, string oldFileName, string newFileName)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text content. - `newText` (string) - Required - The new text content. - `oldFileName` (string) - Required - The name of the old file. - `newFileName` (string) - Required - The name of the new file. ### Returns `string` - The generated unidiff output. ``` ```APIDOC ## Generate (Instance Method) ### Description Generates unified diff format output using an instance of UnidiffRenderer, allowing for custom settings like context lines. ### Method `renderer.Generate(string oldText, string newText, string oldFileName, string newFileName)` ### Parameters #### Path Parameters - `oldText` (string) - Required - The old text content. - `newText` (string) - Required - The new text content. - `oldFileName` (string) - Required - The name of the old file. - `newFileName` (string) - Required - The name of the new file. ### Constructor Parameters #### Path Parameters - `contextLines` (int) - Optional - The number of context lines to include around changes. Defaults to a standard value if not provided. ### Returns `string` - The generated unidiff output. ``` -------------------------------- ### DiffPlex Console Runner Commands Source: https://context7.com/mmanela/diffplex/llms.txt Execute DiffPlex from the command line for unified diff, inline text diff, three-way diff, and merge operations. Supports file and inline text inputs, with options for ignoring whitespace and case. ```bash # Two-file unified diff DiffPlex.ConsoleRunner file old.txt new.txt # Inline text diff DiffPlex.ConsoleRunner text "foo\nbar\n" "foo\nbaz\n" # Three-way diff of files DiffPlex.ConsoleRunner 3way-file base.txt old.txt new.txt # Three-way merge — exits 0 on success, 1 if conflicts exist DiffPlex.ConsoleRunner merge-file base.txt old.txt new.txt # Merge with flags DiffPlex.ConsoleRunner merge-file base.txt old.txt new.txt --ignore-whitespace --ignore-case # Inline text merge DiffPlex.ConsoleRunner merge-text "base\nB\n" "old\nB\n" "base\nNEW\n" ``` -------------------------------- ### Set Text for DiffTextView Source: https://github.com/mmanela/diffplex/blob/master/DiffPlex.Windows/README.md Use the SetText method on a DiffTextView instance to display the old and new text for comparison. ```csharp DiffView.SetText(oldText, newText); ``` -------------------------------- ### UnidiffRenderer.GenerateUnidiff - Generate Git-compatible unified diff output Source: https://context7.com/mmanela/diffplex/llms.txt Renders a diff result into the standard Git-compatible unified diff format, including headers and hunk markers. ```APIDOC ## `UnidiffRenderer` — Generate Git-compatible unified diff output Produces standard unified diff (unidiff) text with `---`/`+++` headers and `@@ ... @@` hunk markers. Both a static `GenerateUnidiff` helper and an instance `Generate` method are provided; the instance form allows configuring context line count. ### Method `UnidiffRenderer.GenerateUnidiff(string oldText, string newText, string oldFileName = null, string newFileName = null, bool ignoreWhitespace = false, bool ignoreCase = false, int contextLines = 1)` `renderer.Generate(string oldText, string newText, string oldFileName = null, string newFileName = null)` `renderer.Generate(DiffResult diffResult, string oldFileName = null, string newFileName = null)` ### Parameters - `oldText` (string) - The original text. - `newText` (string) - The modified text. - `diffResult` (DiffResult) - A pre-computed diff result. - `oldFileName` (string, optional) - The name of the original file. - `newFileName` (string, optional) - The name of the new file. - `ignoreWhitespace` (bool) - Whether to ignore whitespace differences. - `ignoreCase` (bool) - Whether to ignore case differences. - `contextLines` (int) - The number of context lines to include around changes. ### Request Example (Static helper) ```csharp using DiffPlex.Renderer; string patch = UnidiffRenderer.GenerateUnidiff( "line 1\nline 2\nline 3\n", "line 1\nLINE 2\nline 3\n", oldFileName: "original.txt", newFileName: "modified.txt", contextLines: 1); ``` ### Response - `string` - A string containing the unidiff patch, or an empty string if the texts are identical. ``` -------------------------------- ### WPF `DiffViewer` control — Rich diff UI for WPF applications Source: https://context7.com/mmanela/diffplex/llms.txt Provides WPF controls for displaying differences between texts, including line numbers and change markers. ```APIDOC ## WPF `DiffViewer` control — Rich diff UI for WPF applications The `DiffPlex.Wpf` NuGet package provides `DiffViewer`, `SideBySideDiffViewer`, `InlineDiffViewer`, and `ThreeWayMergeViewer` controls. Simply bind `OldText` and `NewText` and the control renders a fully styled diff with line numbers, change markers, and a toggleable split/inline view. ```csharp // MainWindow.xaml — declare namespace at root element: // xmlns:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf" // // // MainWindow.xaml.cs using DiffPlex.Wpf.Controls; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DiffView.OldText = "Hello world\nLine two\n"; DiffView.NewText = "Hello DiffPlex\nLine two\n"; // Switch to inline (unified) view DiffView.SetSideBySide(false); // Styling DiffView.InsertedBackground = System.Windows.Media.Brushes.LightGreen; DiffView.DeletedBackground = System.Windows.Media.Brushes.LightCoral; DiffView.LineNumberWidth = 60; DiffView.IgnoreUnchanged = true; // collapse unchanged sections // Listen for view-mode toggle DiffView.ViewModeChanged += (s, e) => Title = e.IsSideBySideViewMode ? "Split view" : "Inline view"; } } ``` ``` -------------------------------- ### ISideBySideDifferBuilder Interface Definition Source: https://github.com/mmanela/diffplex/blob/master/README.md Defines the contract for building diff models suitable for side-by-side display. This interface is used when you need to generate differences specifically for a visual side-by-side comparison view. ```csharp /// /// 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); } ``` -------------------------------- ### Blazor Diff Components Usage Source: https://context7.com/mmanela/diffplex/llms.txt Utilize Blazor components like DiffViewer and InlineDiffViewer for interactive diff rendering. Pass OldText, NewText, and BaseText properties to display differences. ```razor @* In your Blazor page or component *@ @using DiffPlex.Blazor.Components @code { string OldText = "Hello world\nLine two\n"; string NewText = "Hello DiffPlex\nLine two\n"; string BaseText = "Hello\nLine two\n"; } ```