Skip to content

Conversation

@IEvangelist
Copy link
Member

@IEvangelist IEvangelist commented Oct 4, 2022

Summary

Ported an existing .NET dev blog from @stephentoub into the .NET docs, as a new conceptual article introducing Regex enhancements for .NET 7:

  • Rephrased wording from passive to active.
  • Replaced phrases such as "I" or "we", with "you" where appropriate.
  • Fixed markdown warnings and applied markdown linter fixes where possible.
  • Renamed the image files and ran them through image compression and resizing.
  • Added to TOC with the corresponding title.

Fixes #30289

Preview

@stephentoub
Copy link
Member

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.

@IEvangelist
Copy link
Member Author

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?

@stephentoub
Copy link
Member

Yup :-)

@gewarren gewarren added the 🏁 Release: .NET 7 Work items for the .NET 7 release label Oct 6, 2022
@IEvangelist IEvangelist marked this pull request as ready for review October 11, 2022 15:53
@IEvangelist IEvangelist requested review from a team and adegeo as code owners October 11, 2022 15:54
@IEvangelist IEvangelist changed the title [DRAFT] Ported as conceptual article from .NET dev blog: Regex enhancements with .NET 7 Ported as conceptual article from .NET dev blog: Regex enhancements with .NET 7 Oct 11, 2022
Copy link

@CamSoper CamSoper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's :shipit:

I love your fun string examples.

@IEvangelist IEvangelist merged commit 5ddf794 into dotnet:main Oct 13, 2022
Comment on lines +47 to +50
private static readonly Regex s_abcOrDefGeneratedRegex = AbcOrDefGeneratedRegex();

[GeneratedRegex("abc|def", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")]
private static partial Regex AbcOrDefGeneratedRegex();
Copy link
Member

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;.

Copy link
Member Author

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.

Copy link
Member

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:"

@IEvangelist
Copy link
Member Author

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
Copy link
Member

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?

@IEvangelist IEvangelist added the okr-freshness OKR: Freshness of content label Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏁 Release: .NET 7 Work items for the .NET 7 release dotnet-fundamentals/svc okr-freshness OKR: Freshness of content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create new article introducing Regex source generation enhancements

5 participants