From wpf-dev-pack
Generates compile-time Regex using GeneratedRegexAttribute source generator in C#/.NET 7+ for faster performance, AOT compatibility, and no runtime allocation. Use for validation patterns like email, phone, URL.
npx claudepluginhub christian289/dotnet-with-claudecode --plugin wpf-dev-packThis skill uses the workspace's default tool permissions.
Use `GeneratedRegexAttribute` for compile-time regex generation instead of runtime `new Regex()`.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
Use GeneratedRegexAttribute for compile-time regex generation instead of runtime new Regex().
| Aspect | Runtime Regex | GeneratedRegex |
|---|---|---|
| Compilation | Runtime | Compile-time |
| Performance | Slower first match | Pre-compiled, faster |
| AOT Support | Limited | Full support |
| Memory | Allocates at runtime | No runtime allocation |
| .NET Version | All | .NET 7+ |
public partial class EmailValidator
{
[GeneratedRegex(@"^[\w\.-]+@[\w\.-]+\.\w+$", RegexOptions.IgnoreCase)]
private static partial Regex EmailPattern();
public bool IsValidEmail(string email)
{
return EmailPattern().IsMatch(email);
}
}
Requirements:
partialstatic partial returning Regexpublic partial class ValidationPatterns
{
[GeneratedRegex(@"^[\w\.-]+@[\w\.-]+\.\w+$", RegexOptions.IgnoreCase)]
public static partial Regex Email();
}
[GeneratedRegex(@"^\d{3}-\d{3,4}-\d{4}$")]
public static partial Regex PhoneNumber();
[GeneratedRegex(@"^https?://[\w\.-]+(?:/[\w\.-]*)*$", RegexOptions.IgnoreCase)]
public static partial Regex Url();
[GeneratedRegex(@"\s+")]
private static partial Regex WhitespacePattern();
public string NormalizeWhitespace(string input)
{
return WhitespacePattern().Replace(input, " ");
}
// Anti-pattern: Runtime compilation
public class Validator
{
private static readonly Regex _emailRegex =
new(@"^[\w\.-]+@[\w\.-]+\.\w+$", RegexOptions.Compiled);
public bool IsValid(string email)
{
return _emailRegex.IsMatch(email);
}
}
// Best practice: Compile-time generation
public partial class Validator
{
[GeneratedRegex(@"^[\w\.-]+@[\w\.-]+\.\w+$")]
private static partial Regex EmailPattern();
public bool IsValid(string email)
{
return EmailPattern().IsMatch(email);
}
}
// Multiple options
[GeneratedRegex(@"pattern", RegexOptions.IgnoreCase | RegexOptions.Multiline)]
private static partial Regex MultiOptionPattern();
// With timeout (for untrusted input)
[GeneratedRegex(@"complex.*pattern", RegexOptions.None, matchTimeoutMilliseconds: 1000)]
private static partial Regex SafePattern();
public partial class FormViewModel : ObservableValidator
{
[GeneratedRegex(@"^[\w\.-]+@[\w\.-]+\.\w+$", RegexOptions.IgnoreCase)]
private static partial Regex EmailPattern();
[GeneratedRegex(@"^\d{3}-\d{3,4}-\d{4}$")]
private static partial Regex PhonePattern();
[CustomValidation(typeof(FormViewModel), nameof(ValidateEmail))]
[ObservableProperty] private string _email = string.Empty;
[CustomValidation(typeof(FormViewModel), nameof(ValidatePhone))]
[ObservableProperty] private string _phone = string.Empty;
public static ValidationResult? ValidateEmail(string email, ValidationContext context)
{
if (string.IsNullOrEmpty(email))
return new ValidationResult("Email is required");
if (!EmailPattern().IsMatch(email))
return new ValidationResult("Invalid email format");
return ValidationResult.Success;
}
public static ValidationResult? ValidatePhone(string phone, ValidationContext context)
{
if (string.IsNullOrEmpty(phone))
return ValidationResult.Success; // Optional field
if (!PhonePattern().IsMatch(phone))
return new ValidationResult("Format: 000-0000-0000");
return ValidationResult.Success;
}
}
global using System.Text.RegularExpressions;
partialstatic partial returning RegexRegexOptions for case sensitivity