Skip to content

Add language reference for union types (C# 15) - #52485

Merged
BillWagner merged 19 commits into
dotnet:mainfrom
BillWagner:union-fundamentals
Mar 23, 2026
Merged

Add language reference for union types (C# 15)#52485
BillWagner merged 19 commits into
dotnet:mainfrom
BillWagner:union-fundamentals

Conversation

@BillWagner

@BillWagner BillWagner commented Mar 20, 2026

Copy link
Copy Markdown
Member

Publish the unions.md speclet as part of the overall specification.
A few other language reference articles should reference union types.
Finish the first draft
@BillWagner
BillWagner marked this pull request as ready for review March 20, 2026 18:50
@BillWagner
BillWagner requested a review from a team as a code owner March 20, 2026 18:50
Copilot AI review requested due to automatic review settings March 20, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds C# 15 union types coverage to the C# language reference and related “What’s new”/cross-linking docs, and publishes the unions speclet in the rendered proposal set.

Changes:

  • Adds a new C# reference article for union types plus a full runnable snippet set.
  • Updates C# 15 “What’s new” and other language reference pages to reference unions and union exhaustiveness in pattern matching and switch expressions.
  • Wires the unions speclet into docfx and TOCs.

Reviewed changes

Copilot reviewed 21 out of 21 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 “Union types” section and updates C# 15 intro text and links.
docs/csharp/tour-of-csharp/tips-for-javascript-developers.md Updates JS/TS comparison to note unions are supported starting C# 15.
docs/csharp/specification/toc.yml Adds unions proposal to the specification TOC.
docs/csharp/language-reference/toc.yml Adds “Union types” entry to language reference TOC.
docs/csharp/language-reference/operators/switch-expression.md Adds union-specific exhaustiveness guidance and tweaks heading.
docs/csharp/language-reference/operators/patterns.md Adds union patterns section and refines wording in multiple pattern sections.
docs/csharp/language-reference/builtin-types/value-types.md Adds union types to the “kinds of value types” list.
docs/csharp/language-reference/builtin-types/union.md New reference article describing union declarations, matching, nullability, and manual patterns.
docs/csharp/language-reference/builtin-types/snippets/unions/unions.csproj New snippet project for union type examples (net11/preview).
docs/csharp/language-reference/builtin-types/snippets/unions/Program.cs Entry point running all union snippet scenarios.
docs/csharp/language-reference/builtin-types/snippets/unions/BasicUnion.cs Snippets for basic union declaration, conversions, and pattern matching.
docs/csharp/language-reference/builtin-types/snippets/unions/GenericUnion.cs Snippets for generic union (Option<T>) examples.
docs/csharp/language-reference/builtin-types/snippets/unions/ValueTypeCases.cs Snippets for unions with value-type cases.
docs/csharp/language-reference/builtin-types/snippets/unions/BodyMembers.cs Snippets showing additional members in a union declaration body.
docs/csharp/language-reference/builtin-types/snippets/unions/NullHandling.cs Snippets demonstrating null handling and nullable union usage.
docs/csharp/language-reference/builtin-types/snippets/unions/ManualUnion.cs Snippets for manually implemented union types via attribute/interface pattern.
docs/csharp/language-reference/builtin-types/snippets/unions/NonBoxingAccess.cs Snippets for non-boxing access pattern (HasValue/TryGetValue).
docs/csharp/language-reference/builtin-types/snippets/unions/ClassUnion.cs Snippets for class-based union type implementation and matching.
docs/csharp/language-reference/builtin-types/snippets/unions/MemberProvider.cs Commented-out draft snippet for future “member provider” support.
docs/csharp/language-reference/builtin-types/snippets/unions/RuntimePolyfill.cs Adds a local polyfill for UnionAttribute/IUnion for preview runtimes.
docfx.json Includes the unions proposal in proposal publishing and metadata maps.

Comment thread docs/csharp/language-reference/builtin-types/value-types.md Outdated
Comment thread docs/csharp/language-reference/operators/switch-expression.md
Comment thread docs/csharp/whats-new/csharp-15.md Outdated
Comment thread docs/csharp/whats-new/csharp-15.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/snippets/unions/RuntimePolyfill.cs Outdated
BillWagner and others added 2 commits March 20, 2026 15:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@BillWagner
BillWagner requested review from adegeo and gewarren March 20, 2026 19:34

@MadsTorgersen MadsTorgersen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great!

Comment thread docs/csharp/language-reference/builtin-types/value-types.md Outdated
The *union member providers* aren't in preview 2.
@gewarren gewarren closed this Mar 20, 2026
@gewarren gewarren reopened this Mar 20, 2026

@gewarren gewarren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cool feature

Comment thread docs/csharp/language-reference/toc.yml Outdated
Comment thread docs/csharp/language-reference/operators/patterns.md Outdated
Comment thread docs/csharp/whats-new/csharp-15.md Outdated
Comment thread docs/csharp/whats-new/csharp-15.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/value-types.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/union.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/union.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/union.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/union.md Outdated
Comment thread docs/csharp/language-reference/builtin-types/union.md Outdated
BillWagner and others added 3 commits March 23, 2026 14:09
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Comment thread docs/core/compatibility/library-change-rules.md
Link to the `union` type article and update the date.
@BillWagner
BillWagner merged commit e68b5dd into dotnet:main Mar 23, 2026
9 checks passed
@BillWagner
BillWagner deleted the union-fundamentals branch March 23, 2026 21:40
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.

4 participants