dotnet-source-gen-regex
Converts Regex instances to use the compile-time source generator.
Skill by Im5tu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/im5tu-dotnet-source-gen-regex
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/dotnet-source-gen-regex
Tools it pre-approves 7
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
Bash(dotnet:*),Read,Edit,Write,Glob,Grep,AskUserQuestion
What's inside
- Skill name
dotnet-source-gen-regex- Description
- Converts Regex instances to use the compile-time source generator. Also use when the user mentions "GeneratedRegex," "regex source generator," "compile-time regex," "AOT regex," "optimize regex," or "source-generated regex." For full AOT analysis, see dotnet-aot-analysis.
- License
- MIT
- Allowed tools
- Bash(dotnet:*),, Read,, Edit,, Write,, Glob,, Grep,, AskUserQuestion
- Metadata
- author: Im5tu · version: 1.0 · repositoryUrl: https://github.com/im5tu/dotnet-skills
- Instructions
- 92 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves some shell commands
Files (1)
- SKILL.md
SKILL.md (first lines)
# .NET Regex Source Generator
The regex source generator creates compile-time generated regex implementations that are:
- **AOT-compatible**: Works with Native AOT and trimming
- **Debuggable**: Step through the generated matching code
- **Performant**: No runtime compilation overhead
## When to Use
This skill applies when the user:
- Wants to optimize regex performance
- Needs AOT-compatible regex patterns
- Asks about `[GeneratedRegex]` attribute
- Mentions converting `new Regex(...)` to source-generated
- Discusses regex compilation or startup performance
## Workflow
1. **Find regex usages** in the codebase:
- `new Regex(...)` constructor calls
- `Regex.IsMatch()`, `Regex.Match()`, `Regex.Replace()` static method calls
- Other static `Regex.*` methods with inline patterns
2. **For each regex with a compile-time known pattern**:
- Ensure the containing class is `partial`
- Create a partial method with `[GeneratedRegex]` attribute:
```csharp
[GeneratedRegex("pattern", RegexOptions.IgnoreCase)]
private static partial Regex MyRegex();
```
- Name the method descriptively based on what the pattern matches
3. **Replace usages** to call the generated method:
```csharp
// Before
var regex = new Regex(@"\d+", RegexOptions.Compiled);
if (regex.IsMatch(input)) { ... }
// After
if (MyNumberRegex().IsMatch(input)) { ... }
[GeneratedRegex(@"\d+")]
private static partial Regex MyNumberRegex();
```
4. **Verify** with `dotnet build`
5. **If build fails**, check:
- Class is marked `partial`
- Pattern is a compile-time constant
- .NET version is 7 or higher
## Key Notes
| Note | Detail |
|------|--------|
| `RegexOptions.Compiled` | Ignored by source gen - remove it |
| .NET Version | Requires .NET 7+ |
| Caching | Generated method caches singleton internally |
| Timeout | Use `[GeneratedRegex("pattern", RegexOptions.None, 1000)]` for timeout (milliseconds) |
## Pattern Conversion Examples
**Instance with options:**
```csharp
// Before
private readonly Regex _emailRegex = new(@"^[\w-\.]+@[\w-]+\.\w+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
// After
[GeneratedRegex(@"^[\w-\.]+@[\w-]+\.\w+$", RegexOptions.IgnoreCase)]
private static partial Regex EmailRegex();
```
**Static method call:**
```csharp
// Before
if (Regex.IsMatch(input, @"^\d{3}-\d{4}$"))
// After
if (PhoneNumberRegex().IsMatch(input))
[GeneratedRegex(@"^\d{3}-\d{4}$")]
private static partial Regex PhoneNumberRegex();
```
## Error Handling
- **If pattern is not constant**: Cannot use source gen - leave as runtime regex
- **If class is not partial**: Add `partial` modifier to the class declaration
- **If build fails after conversion**: Check error messages for unsupported pattern featuresFrom Im5tu/claude, MIT.
More from Im5tu/claude
- 0.587score
website-seo
Im5tu
When the user wants SEO strategy, audits, technical SEO, schema markup, content architecture, or search visibility optimization.
SkillBFreshness: B★ 6Claude Code - 0.587score
website-design
Im5tu
When the user wants to design and build a premium multi-page website for any business type.
SkillBFreshness: B★ 6Claude Code - 0.582score
dotnet-centralise-packages
Im5tu
Converts a .NET solution to use Central Package Management (CPM).
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-json-polymorphic
Im5tu
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-json
Im5tu
Configures System.Text.Json source generation for AOT-compatible JSON serialization.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-logging
Im5tu
Converts logging to use the LoggerMessage source generator for high-performance, AOT-compatible logging.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-source-gen-options-validation
Im5tu
Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-update-packages
Im5tu
Lists and updates outdated NuGet packages in .NET projects.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-enable-testing-platform
Im5tu
Enables the Microsoft Testing Platform runner in global.json.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-aot-analysis
Im5tu
Analyzes and configures a .NET project or solution for Native AOT compatibility.
SkillBFreshness: B★ 6Claude Code +9 - 0.548score
plan-feature
Im5tu
Interview user in-depth to create a detailed spec.
SkillBFreshness: B★ 6Claude Code +9 - 0.463score
reprompt
Im5tu
Formats input into Goal, Constraints, Format, Failure structure.
SkillDFreshness: D★ 6Claude Code +9
Signals
- Stars
- 6
- Forks
- 3
- Open issues
- 0
- Last commit (this folder)
- Aug 21, 2026 (2 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0
- License
- MIT
- Repository
- github.com/Im5tu/claude
- Website
- codewithstu.tv
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Im5tu
- 0.587score
website-design
Im5tu
When the user wants to design and build a premium multi-page website for any business type.
SkillBFreshness: B★ 6Claude Code - 0.587score
website-seo
Im5tu
When the user wants SEO strategy, audits, technical SEO, schema markup, content architecture, or search visibility optimization.
SkillBFreshness: B★ 6Claude Code - 0.582score
dotnet-enable-testing-platform
Im5tu
Enables the Microsoft Testing Platform runner in global.json.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-aot-analysis
Im5tu
Analyzes and configures a .NET project or solution for Native AOT compatibility.
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-centralise-packages
Im5tu
Converts a .NET solution to use Central Package Management (CPM).
SkillBFreshness: B★ 6Claude Code +9 - 0.582score
dotnet-json-polymorphic
Im5tu
Configures polymorphic JSON serialization with [JsonPolymorphic] and [JsonDerivedType] attributes.
SkillBFreshness: B★ 6Claude Code +9
Cite this page
dotnet-source-gen-regex skill. Agent Mart. https://agentmart.dev/skills/im5tu-dotnet-source-gen-regex (last updated 2026-10-24)