https://github.com/thomashambach/csharpdiff
C# Diff with Unified Diff Support
https://github.com/thomashambach/csharpdiff
csharp csharp-library diff dotnet unidiff
Last synced: 2 months ago
JSON representation
C# Diff with Unified Diff Support
- Host: GitHub
- URL: https://github.com/thomashambach/csharpdiff
- Owner: ThomasHambach
- License: mit
- Created: 2022-08-19T13:33:43.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-09T09:58:54.000Z (over 1 year ago)
- Last Synced: 2025-04-05T13:02:40.343Z (2 months ago)
- Topics: csharp, csharp-library, diff, dotnet, unidiff
- Language: C#
- Homepage:
- Size: 70.3 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://sonarcloud.io/summary/new_code?id=ThomasHambach_csharpdiff) [](https://sonarcloud.io/summary/new_code?id=ThomasHambach_csharpdiff) [](https://www.nuget.org/packages/CSharpDiff) [](LICENSE) [](https://github.com/thomashambach/csharpdiff/graphs/contributors)
# CSharpDiff
C# Diff with Unified Diff Support, this codebase is a port from the popular JS library [jsdiff](https://github.com/kpdecker/jsdiff) by [kpdecker](https://github.com/kpdecker).
## Todo
- [ ] Clean-up code (Code smells and bugs according to Sonar)
- [ ] Patch
- [x] Create
- [ ] Apply
- [ ] Merge
- [ ] Parse
- [ ] Diff
- [ ] Array
- [x] Base `Diff()`
- [x] Character `Diff()`
- [ ] CSS
- [ ] JSON
- [x] Line `DiffLines()`
- [x] Sentence `DiffSentence()`
- [ ] Word (Partial, issues with Regex in `DiffWord.Tokenize`)
- [x] Convert `DiffConvert`
- [x] XML `DiffConvert.ToXml`
- [x] DMP (diff-match-patch) `DiffConvert.ToDmp`## Usage Example
### Diff
#### Character
```c#
using CSharpDiff.Diff;var diff = new Diff(new DiffOptions
{
IgnoreCase = true
});
var result = diff.diff("New Value.", "New value.");
```#### Line
```c#
using CSharpDiff.Diff;var text1 = "Here im.\nRock you like old man.\nYeah";
var text2 = "Here im.\nRock you like hurricane.\nYeah";var diff = new DiffLines();
var difference = diff.diff(text1, text2);
```#### Sentence
```c#
using CSharpDiff.Diff;var text1 = "Here im. Rock you like old man.";
var text2 = "Here im. Rock you like hurricane.";var diff = new DiffSentence();
var difference = diff.diff(text1, text2);
```### Patch
#### Create
```c#
using CSharpDiff.Patch;var text1 = "...";
var text2 = "...";var ps = new Patch();
string patch = ps.create("filename1", "filename2", text1, text2, "header1", "header2", new PatchOptions());
```### Works Well With
* [Diff2HTML](https://diff2html.xyz/)
## Contributing
Idk, just make a pull request.