docs icon indicating copy to clipboard operation
docs copied to clipboard

[C# 14-Tutorials]: New Feature - Extensions

Open BillWagner opened this issue 8 months ago • 2 comments

Visual Studio release

17.14.p4

Link to speclet

Link to Pull request

New behavior

The new syntax supports extension containers to define extension members, including properties, indexers, and operators. It's generally binary compatible with the existing syntax, so upgrading should be smooth.

New tutorials

The additional extensions is a major new feature area. This one deserves two exploratory tutorials:

  1. Create new types of extensions, including properties, operators, and indexers.
  2. Migrate a set of extensions from the existing this syntax to the new syntax. This should include multiple extension containers (for different receivers) on the same static class. Include some generic specializations.

Associated WorkItem - 417140

BillWagner avatar Apr 02 '25 20:04 BillWagner

Scenario notes: Make a set of extensions to create a scenario based interface for a closed generic type. Something like Dictionary<DateOnly,WeatherForecast> or similar.

BillWagner avatar May 01 '25 22:05 BillWagner

See this blog comment: https://devblogs.microsoft.com/dotnet/csharp-exploring-extension-members/?commentid=22057#comment-22057

This set of tutorials should include examples of extending a static class. Perhaps File or Directory, as shown in the blog comment, or Math would be a good set of scenarios.

BillWagner avatar May 12 '25 17:05 BillWagner