Add language reference for union types (C# 15)#52485
Open
BillWagner wants to merge 13 commits intodotnet:mainfrom
Open
Add language reference for union types (C# 15)#52485BillWagner wants to merge 13 commits intodotnet:mainfrom
union types (C# 15)#52485BillWagner wants to merge 13 commits intodotnet:mainfrom
Conversation
Publish the unions.md speclet as part of the overall specification.
Refactor the sample into a better organization.
A few other language reference articles should reference union types.
Finish the first draft
Contributor
There was a problem hiding this comment.
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. |
docs/csharp/language-reference/builtin-types/snippets/unions/RuntimePolyfill.cs
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/builtin-types/snippets/unions/NonBoxingAccess.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The *union member providers* aren't in preview 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributes to #52320
This PR handles the language reference and What's new changes. The fundamentals changes will be added later.
Internal previews
isandswitchexpressions, and operatorsand,or, andnotin patterns