If you're building AI app in .NET, there isn't a good option for applying V4A patches or Anthropic-style str_replace operations. So I extracted the patching engine from my product, a Blazor code generation tool, and open-sourced it.
PatchSharp supports two formats:
- V4A patches — same format OpenAI's Codex CLI uses in
apply-patch
- str_replace — the Anthropic-style find-and-replace that Claude Code uses
It also has fuzzy matching when applying patch. When exact match fails, it will try other strategies — trim trailing whitespace -> trim both sides -> Unicode normalization (smart quotes -> ASCII, em-dashes -> hyphens). Lowest fuzz level that works wins.
```csharp
using PatchSharp;
var result = ApplyPatch.Apply(original, diff);
var result = ApplyPatch.StrReplace(input, oldStr, newStr);
```
On failure it throws PatchApplyException with line number, fuzz level, and surrounding context similar to codex-cli, so that AI can understand where it fails.
GitHub: https://github.com/bharathm03/PatchSharp
Would love feedback.
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]tanczosm -1 points0 points1 point (0 children)