Skip to content

Add closed hierarchies for C# 15, preview 5#54128

Open
BillWagner wants to merge 14 commits into
dotnet:mainfrom
BillWagner:closed-hierarchies-reference
Open

Add closed hierarchies for C# 15, preview 5#54128
BillWagner wants to merge 14 commits into
dotnet:mainfrom
BillWagner:closed-hierarchies-reference

Conversation

@BillWagner
Copy link
Copy Markdown
Member

@BillWagner BillWagner commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds C# 15 Preview 5 documentation for the new closed modifier (closed class hierarchies), including a new language reference article, updated pattern matching guidance on exhaustiveness/subsumption, a “What’s new” entry, and publication wiring for the feature specification.

Changes:

  • Add closed modifier reference content and link it into the keyword index and TOC.
  • Extend pattern matching docs with a new “Closed hierarchy patterns” section and new snippets.
  • Publish the closed-hierarchies proposal content via spec TOC and docfx.json configuration.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/csharp/whats-new/csharp-15.md Adds “Closed hierarchies” to the C# 15 preview feature list with examples and links.
docs/csharp/specification/toc.yml Adds “Closed hierarchies” entry to the specification TOC pointing at the proposal.
docs/csharp/language-reference/toc.yml Adds closed keyword entry to the language reference TOC.
docs/csharp/language-reference/operators/snippets/patterns/patterns.csproj Updates snippet project TFM to net11.0 (but needs LangVersion for preview syntax).
docs/csharp/language-reference/operators/snippets/patterns/ClosedHierarchyPatterns.cs Introduces new closed-hierarchy pattern matching snippets and narrative comments.
docs/csharp/language-reference/operators/patterns.md Adds “Closed hierarchy patterns” section explaining exhaustiveness, accessibility, and subsumption.
docs/csharp/language-reference/keywords/snippets/shared/Closed.cs Adds shared closed keyword snippets for the reference article.
docs/csharp/language-reference/keywords/snippets/keywords.csproj Updates snippet project TFM to net11.0-windows (but needs LangVersion for preview syntax).
docs/csharp/language-reference/keywords/index.md Adds closed to the contextual keywords list.
docs/csharp/language-reference/keywords/closed.md Adds the new closed modifier reference article and links to related guidance/spec.
docfx.json Wires in the new proposal file for build/metadata/title/description.
Comments suppressed due to low confidence (1)

docs/csharp/language-reference/keywords/snippets/keywords.csproj:12

  • The keywords snippet project now targets net11.0-windows and includes C# 15 preview syntax (the closed modifier), but the project doesn't set LangVersion to preview. If the build defaults to a stable language version, the new closed snippets won't compile.
  <PropertyGroup>
    <ImplicitUsings>enable</ImplicitUsings>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net11.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <StartupObject>Keywords.Program</StartupObject>
    <GenerateDocumentationFile>False</GenerateDocumentationFile>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

Comment thread docs/csharp/language-reference/operators/patterns.md Outdated
Comment thread docs/csharp/language-reference/keywords/closed.md
Comment thread docfx.json Outdated
Comment thread docs/csharp/whats-new/csharp-15.md
@BillWagner BillWagner marked this pull request as ready for review June 5, 2026 14:36
@BillWagner BillWagner requested a review from a team as a code owner June 5, 2026 14:36
@BillWagner
Copy link
Copy Markdown
Member Author

@adegeo @gewarren

I'm marking this ready for review. The snippets build will pass once preview 5 ships for our preview containers.

I'd like to merge this when Preview 5 ships, so can I get reviews and approvals before then?

BillWagner and others added 13 commits June 5, 2026 11:13
Publish the feature spec for closed hierarchies.
Add a new reference article for `closed`. Update snippets and the associated TOC.
The `closed` hierarchy impacts pattern exhaustiveness and subsumption. Add a section to discuss that in the patterns reference article.
Add the `closed` contextual keyword to the What's new in C# 15 article.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Add note on exhaustiveness checks for type parameters.
Developers need to define the required attribute in Preview 5.
The first samples all used the same code. Show different scenarios that could be good for closed class hierarchies.
@BillWagner BillWagner force-pushed the closed-hierarchies-reference branch from 9e50107 to c070249 Compare June 5, 2026 15:13
Comment thread docs/csharp/language-reference/keywords/closed.md Outdated
Comment thread docs/csharp/language-reference/operators/patterns.md Outdated
Comment thread docs/csharp/language-reference/operators/patterns.md Outdated
Copy link
Copy Markdown
Contributor

@wadepickett wadepickett left a comment

Choose a reason for hiding this comment

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

Approved. Looks great! I found a couple very minor items. My suggestions are inline.

Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C# 15-Reference]: New Feature - Closed class hierarchies

3 participants