dotnet-source-gen-regex

Convert compile-time known regex patterns into GeneratedRegex methods for .NET 7 or higher.

6|2|Updated Aug 14, 2025
One-click install
npx skills add https://github.com/Im5tu/claude --skill dotnet-source-gen-regex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-source-gen-regex
Source: https://github.com/Im5tu/claude/tree/main/skills/dotnet-source-gen-regex
Command: npx skills add https://github.com/Im5tu/claude --skill dotnet-source-gen-regex

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill converts compile-time known regex patterns into GeneratedRegex-based implementations to optimize performance.

Core Features & Use Cases

  • Source-generated regex: Replace runtime Regex usage with pre-generated methods to improve startup and runtime performance.
  • AOT-compatible: Generates patterns that are compatible with Ahead-Of-Time compilation and trimming.
  • Use Case: In projects with many patterns, migrate multiple areas to GeneratedRegex for faster matches.

Quick Start

Use the dotnet-source-gen-regex skill to scan for patterns that can be converted, and generate corresponding GeneratedRegex methods in your partial classes.

Frequently Asked Questions about dotnet-source-gen-regex

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert regex patterns to source-generated code in .NET?

To convert regex patterns to source-generated code, you use the [GeneratedRegex] attribute on a method within a partial class. This requires .NET 7 or higher to compile the pre-generated regex methods and optimize runtime performance.

Does .NET source generation work with AOT compilation and trimming?

Yes, source-generated regex is fully AOT-compatible. Using the [GeneratedRegex] attribute creates patterns compatible with Ahead-Of-Time compilation and trimming, replacing runtime regex usage to improve startup speed.

What is the benefit of using GeneratedRegex over runtime regex?

GeneratedRegex replaces runtime regex usage with pre-generated methods to improve both startup and runtime performance. It converts compile-time known regex patterns into optimized, AOT-ready code within your .NET projects.

Do I need a partial class for .NET regex source generation?

Yes, a partial class is required for .NET regex source generation. The skill generates corresponding GeneratedRegex methods in your partial classes, requiring .NET 7 or higher and the [GeneratedRegex] attribute to compile.

Can I migrate multiple runtime regex areas to GeneratedRegex in one project?

Yes, you can scan for compile-time known regex patterns across multiple classes and APIs. The skill generates corresponding GeneratedRegex methods for each pattern found, migrating multiple areas to faster matches.

Why does my source-generated regex require .NET 7 or higher?

Source-generated regex requires .NET 7 or higher because the [GeneratedRegex] attribute and its underlying source generation features were introduced in that version. Older .NET versions lack the necessary compiler support.