Use the [GeneratedRegex] source generator for ALL regex in .NET 7+ C#. Produces AOT-safe, trimming-friendly, compile-time regex with zero startup cost and better throughput than RegexOptions.Compiled. Trigger whenever the user writes, reviews, or asks about regex in C# — including new Regex(...), Regex.IsMatch, pattern matching, string validation, or text parsing — even if they don't mention source generation. Never suggest new Regex(...) with RegexOptions.Compiled when [GeneratedRegex] is available.
Installation
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Use the [GeneratedRegex] source generator for ALL regex in .NET 7+ C#. Produces AOT-safe, trimming-friendly, compile-time regex with zero startup cost and better throughput than RegexOptions.Compiled. Trigger whenever the user writes, reviews, or asks about regex in C# — including new Regex(...), Regex.IsMatch, pattern matching, string validation, or text parsing — even if they don't mention source generation. Never suggest new Regex(...) with RegexOptions.Compiled when [GeneratedRegex] is available.
C# Source-Generated Regex Skill
Use [GeneratedRegex] on a partial method or property so the compiler emits a fully-optimised, AOT-safe Regex implementation at build time. This delivers the throughput of RegexOptions.Compiled with near-zero startup cost, and the output is ordinary C# that you can read and debug.
Why this matters
new Regex(pattern, RegexOptions.Compiled) pays a heavy startup cost (reflection-emit, JIT compilation) and is not AOT-safe. [GeneratedRegex] compiles the pattern into readable C# during the build, giving you:
Better throughput than RegexOptions.Compiled (and more, in some benchmarks)
Near-zero startup cost — no JIT compile at runtime
AOT / trimming safe — no Reflection.Emit
Debuggable — step through the generated C# in any debugger
Automatic singleton caching — no static readonly field needed
Diagnostic SYSLIB1045 fires when the compiler detects a place that could use [GeneratedRegex] but doesn't.