-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Ported as conceptual article from .NET dev blog: Regex enhancements with .NET 7
#31587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks, @IEvangelist. Though FWIW I find this out-of-place. It's one thing to have conceptual docs about GeneratedRegex, but this post was about things that are new in .NET 7; it's not limited to just the source generator, there's a lot of implementation detail in here, and there's a lot more to regex than just what's discussed in this post, since it's written about the delta from .NET 6 to .NET 7. |
Thanks, @stephentoub. This is still a draft, with lots of plans for stripping it down - I haven't gotten that far yet. There is a ton of great info in this post, and I want the conceptual parts to remain after I shake away the implementation details. The current title was an initial thought, but this is all in flux right now, but will most likely be hyperfocused on the source generation bits. Give me a bit to work on this more, and I'll tag you for review when it's ready. Is that fair? |
|
Yup :-) |
9d072ce to
e7527ae
Compare
Regex enhancements with .NET 7Regex enhancements with .NET 7
CamSoper
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let's ![]()
I love your fun string examples.
docs/standard/base-types/snippets/regular-expression-source-generators/Program.cs
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
docs/standard/base-types/regular-expression-source-generators.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Genevieve Warren <[email protected]>
| private static readonly Regex s_abcOrDefGeneratedRegex = AbcOrDefGeneratedRegex(); | ||
|
|
||
| [GeneratedRegex("abc|def", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")] | ||
| private static partial Regex AbcOrDefGeneratedRegex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no benefit to caching this into a static field. The source generator does that itself. If you look at the generated code for this, you'll see the generated AbcOrDefGeneratedRegex method is essentially just AbcOrDefGeneratedRegex() => s_cachedField;.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the purpose of this section was to show exactly what the analyzer with the applied fix will do, I can adjust this. The analyzer's applied fix though doesn't behave this way, instead, it will re-write your code like the resulting code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The analyzer isn't mentioned in this section. The description of this code sample states: "You can now rewrite the previous code as follows:"
|
Thanks for the feedback @stephentoub, I've addressed it in #31758. |
|
|
||
| :::image type="content" source="media/regular-expression-source-generators/xml-comments.png" lightbox="media/regular-expression-source-generators/xml-comments.png" alt-text="Generated XML comments describing regex"::: | ||
|
|
||
| ## Inside the source-generated files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much of this section is about implementation detail. Is it all relevant to the docs?
Summary
Ported an existing .NET dev blog from @stephentoub into the .NET docs, as a new conceptual article introducing
Regexenhancements for .NET 7:Fixes #30289
Preview