This project demonstrates comprehensive usage of the TextDiff.Sharp library through practical examples.
- .NET 8.0 or later
- The TextDiff.Sharp library (referenced locally)
dotnet runThis starts an interactive menu where you can choose from available examples:
Available Examples:
1. Basic Diff Processing
2. Async Processing with Cancellation
3. Memory-Optimized Processing
4. Streaming for Large Files
5. Error Handling Patterns
6. Progress Reporting
7. Custom Dependencies
8. Real-World Scenario
9. Performance Comparison
0. Exit
dotnet run [example-number]Examples:
dotnet run 1- Basic diff processingdotnet run 2- Async processing demonstrationdotnet run 5- Error handling patterns
- Basic Diff Processing: Fundamental diff application with sample files
- Error Handling: Comprehensive error handling patterns and best practices
- Memory-Optimized Processing: Memory-efficient processing for large files
- Performance Comparison: Benchmarking different processing methods
- Streaming Processing: Stream-to-stream processing for very large files
- Async Processing: Asynchronous processing with cancellation and progress reporting
- Progress Reporting: Real-time progress updates for long-running operations
- Custom Dependencies: Using custom implementations of core interfaces
- Code Review System: Simulated code review workflow
- Document Version Management: Version control scenario
The SampleFiles/ directory contains:
sample_document.txt- Original JavaScript codesample_diff.txt- Unified diff with improvementsupdated_document.txt- Generated result (created when running examples)
var differ = new TextDiffer();
var result = differ.Process(originalDocument, diffContent);var result = await differ.ProcessAsync(
document,
diff,
cancellationToken,
progress);var result = differ.ProcessOptimized(
largeDocument,
diff,
bufferSizeHint: 16384);var result = await differ.ProcessStreamsAsync(
documentStream,
diffStream,
outputStream);try {
var result = differ.Process(document, diff);
} catch (InvalidDiffFormatException ex) {
Console.WriteLine($"Invalid diff at line {ex.LineNumber}");
} catch (DiffApplicationException ex) {
Console.WriteLine($"Application failed: {ex.Message}");
}var progress = new Progress<ProcessingProgress>(p =>
Console.WriteLine($"{p.Stage}: {p.PercentComplete:F1}%"));
var result = await differ.ProcessAsync(document, diff, token, progress);- Start with Example 1 - Basic diff processing concepts
- Try Example 5 - Understand error handling patterns
- Explore Example 2 - Learn async processing
- Experiment with Example 3 - Memory optimization techniques
- Advanced scenarios - Examples 7-9 for production patterns
- Create a new class in the
Examples/directory - Implement a static
Run()method - Add the example to the menu in
Program.cs
Example 7 demonstrates how to create custom implementations of:
IDiffBlockParser- Custom diff parsing logicIContextMatcher- Custom context matching algorithmsIChangeTracker- Custom change tracking and reporting
- Examples 3 and 9 demonstrate performance optimization techniques
- Memory usage is measured and reported for comparison
- Processing times vary based on document size and complexity
- Use streaming (Example 4) for files larger than 100MB
If you encounter issues:
- Ensure .NET 8.0+ is installed
- Verify the TextDiff.Sharp project builds successfully
- Check that sample files exist in
SampleFiles/ - Run
dotnet buildto verify compilation
For more help, see the main project documentation or troubleshooting guide.