enforcing-generated-regex

Enforce the [GeneratedRegex] Source Generator attribute for C# Regex performance optimization.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/christian289/task_20260212 --skill enforcing-generated-regex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: enforcing-generated-regex
Source: https://github.com/christian289/task_20260212/tree/main/.claude/skills/enforcing-generated-regex
Command: npx skills add https://github.com/christian289/task_20260212 --skill enforcing-generated-regex

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires GeneratedRegex, and includes scripts (resource) components.

What problem does it solve?

This Skill ensures that Regex expressions in C# are optimized using the [GeneratedRegex] Source Generator attribute, improving compile-time performance.

Core Features & Use Cases

  • Source Generator Attribute:强制使用[GeneratedRegex]属性,编译时优化正则表达式。
  • Compile-Time Optimization:通过Source Generator在编译时生成优化后的代码,减少运行时开销。
  • Use Case:适用于需要频繁使用正则表达式且对性能要求较高的应用程序,如数据验证、格式化等。

Quick Start

Apply the [GeneratedRegex] attribute to a Regex pattern in your C# code to enable compile-time optimization.

Frequently Asked Questions about enforcing-generated-regex

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

FAQPage Schema
How do I optimize Regex performance in C# for string processing?

To optimize Regex performance in C#, apply the [GeneratedRegex] attribute to your patterns. This utilizes a Source Generator to compile optimized code at compile-time, significantly reducing runtime overhead during string processing.

What is the [GeneratedRegex] Source Generator attribute in C#?

The [GeneratedRegex] attribute is a C# feature that triggers a Source Generator to optimize Regex expressions at compile-time, moving the pattern parsing overhead from application runtime to the build phase.

Does C# Source Generator regex optimization work for data validation?

Yes, enforcing the [GeneratedRegex] attribute is specifically designed for high-performance scenarios like data validation and string processing where Regex expressions are frequently used and application performance is critical.

How to enforce the GeneratedRegex attribute for C# compile-time optimization?

You enforce compile-time optimization by applying the [GeneratedRegex] attribute directly to your Regex pattern definitions within your C# codebase to ensure Source Generator support is utilized.

Do I need a specific C# compiler to use Source Generator regex attributes?

Yes, enforcing the [GeneratedRegex] attribute requires a C# compiler that explicitly supports Source Generators to successfully generate the compile-time optimized code for your Regex expressions.