-
-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
Description (optional)
Support for [GeneratedRegex] attribute. MS Docs
Rationale
This is the new .Net 8 way of having static readonly regexes in code:
[GeneratedRegex(@"^by\(\s*(?<var>[a-zA-Z_][a-zA-Z0-9_]*)\s*\)")]
private static partial Regex MyRegex();
private static readonly Regex _byForm = MyRegex();Prior to .Net 8, this is required:
private static readonly Regex _byForm = new(@"^by\(\s*(?<var>[a-zA-Z_][a-zA-Z0-9_]*)\s*\)");which is arguably cleaner, but it means that regex table lookups are performed at runtime instead of at compile time. (I expect my usage isn't an ideal example.)
Proposed API
No proposal
Drawbacks
None
Alternatives
None
Other thoughts
None.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels