Rework pattern matching fundamentals - #55966
BillWagner wants to merge 4 commits into
Conversation
First draft of changes
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved cross-article union-pattern and null-matching inconsistencies should be corrected before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Reorganizes C# pattern-matching Fundamentals content into a dedicated Patterns section with new articles, examples, updated links, and redirects.
Changes:
- Adds pattern-matching overview, declaration, constant,
var, and type-pattern guidance. - Relocates snippets and updates navigation and cross-references.
- Preserves legacy URLs through redirects.
Review notes: Three nit-level documentation issues remain: clarify null matching for unions and synchronize union-pattern exception guidance across Fundamentals and language-reference content.
File summaries
| File | Summary |
|---|---|
docs/fundamentals/code-analysis/style-rules/ide0083.md |
Updates pattern-matching link. |
docs/fundamentals/code-analysis/style-rules/ide0078-ide0260.md |
Updates pattern-matching link. |
docs/fundamentals/code-analysis/style-rules/ide0060.md |
Updates discard link. |
docs/fundamentals/code-analysis/style-rules/ide0059.md |
Updates discard link. |
docs/fundamentals/code-analysis/style-rules/ide0058.md |
Updates discard link. |
docs/fundamentals/code-analysis/style-rules/ide0020-ide0038.md |
Updates pattern-matching links. |
docs/fundamentals/code-analysis/style-rules/ide0019.md |
Updates pattern-matching links. |
docs/fundamentals/code-analysis/quality-rules/ca1801.md |
Updates discard link. |
docs/csharp/whats-new/tutorials/unions.md |
Updates overview link. |
docs/csharp/whats-new/tutorials/closed-hierarchies.md |
Updates overview link. |
docs/csharp/whats-new/csharp-version-history.md |
Updates pattern and discard links. |
docs/csharp/tour-of-csharp/tutorials/pattern-matching.md |
Links to the new overview and reference. |
docs/csharp/tour-of-csharp/tutorials/branches-and-loops.md |
Updates pattern-matching link. |
docs/csharp/tour-of-csharp/tips-for-python-developers.md |
Updates pattern-matching link. |
docs/csharp/tour-of-csharp/tips-for-javascript-developers.md |
Updates pattern-matching links. |
docs/csharp/tour-of-csharp/tips-for-java-developers.md |
Updates pattern-matching link. |
docs/csharp/tour-of-csharp/overview.md |
Updates pattern-matching links. |
docs/csharp/tour-of-csharp/index.yml |
Renames the Fundamentals navigation item. |
docs/csharp/toc.yml |
Adds the Patterns TOC section. |
docs/csharp/misc/cs0077.md |
Updates pattern-matching link. |
docs/csharp/language-reference/operators/patterns.md |
Updates overview link. |
docs/csharp/language-reference/operators/member-access-operators.md |
Links directly to list patterns. |
docs/csharp/language-reference/operators/lambda-expressions.md |
Updates discard link. |
docs/csharp/language-reference/operators/delegate-operator.md |
Updates discard link. |
docs/csharp/language-reference/compiler-messages/tuple-errors.md |
Updates pattern-matching link. |
docs/csharp/language-reference/compiler-messages/record-declaration-errors.md |
Updates pattern-matching links. |
docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md |
Updates discard link. |
docs/csharp/language-reference/compiler-messages/deconstruction-errors.md |
Updates discard links. |
docs/csharp/language-reference/builtin-types/value-tuples.md |
Updates pattern-matching link. |
docs/csharp/language-reference/builtin-types/union.md |
Documents union pattern exceptions. |
docs/csharp/index.yml |
Updates landing-page navigation. |
docs/csharp/fundamentals/types/tuples.md |
Updates discard links. |
docs/csharp/fundamentals/types/enums.md |
Updates pattern-matching links. |
docs/csharp/fundamentals/types/delegates-lambdas.md |
Updates pattern-matching link. |
docs/csharp/fundamentals/types/conversions.md |
Updates pattern-matching link. |
docs/csharp/fundamentals/tutorials/system-command-line.md |
Updates pattern links. |
docs/csharp/fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md |
Updates pattern-matching link. |
docs/csharp/fundamentals/statements/selection.md |
Updates pattern-matching links. |
docs/csharp/fundamentals/patterns/type-patterns.md |
Adds type-pattern guidance. |
docs/csharp/fundamentals/patterns/snippets/patterns/TypePatterns.cs |
Adds type-pattern examples. |
docs/csharp/fundamentals/patterns/snippets/patterns/Program.cs |
Runs pattern examples. |
docs/csharp/fundamentals/patterns/snippets/patterns/patterns.csproj |
Configures the pattern sample project. |
docs/csharp/fundamentals/patterns/snippets/patterns/Overview.cs |
Adds overview examples. |
docs/csharp/fundamentals/patterns/snippets/patterns/BasicPatterns.cs |
Adds basic-pattern examples. |
docs/csharp/fundamentals/patterns/snippets/discards/standalone-discard2.cs |
Adds discard identifier examples. |
docs/csharp/fundamentals/patterns/snippets/discards/standalone-discard1.cs |
Adds standalone discard examples. |
docs/csharp/fundamentals/patterns/snippets/discards/Program.cs |
Runs discard examples. |
docs/csharp/fundamentals/patterns/snippets/discards/discards.csproj |
Defines the discard sample project. |
docs/csharp/fundamentals/patterns/snippets/discards/discard-tuple.cs |
Adds a tuple discard example. |
docs/csharp/fundamentals/patterns/snippets/discards/discard-pattern2.cs |
Adds a discard-pattern example. |
docs/csharp/fundamentals/patterns/snippets/discards/discard-out1.cs |
Adds an out discard example. |
docs/csharp/fundamentals/patterns/snippets/discards/discard-class.cs |
Adds an object deconstruction example. |
docs/csharp/fundamentals/patterns/pattern-matching.md |
Adds the pattern-matching overview. |
docs/csharp/fundamentals/patterns/discards.md |
Reworks discard guidance. |
docs/csharp/fundamentals/patterns/declaration-constant-var-patterns.md |
Adds declaration, constant, and var pattern guidance. |
docs/csharp/fundamentals/functional/snippets/patterns/Simulation.cs |
Removes superseded snippets. |
docs/csharp/fundamentals/functional/snippets/patterns/Program.cs |
Removes superseded snippets. |
docs/csharp/fundamentals/functional/snippets/patterns/OrderProcessor.cs |
Removes superseded snippets. |
docs/csharp/fundamentals/functional/snippets/patterns/ListPattern.cs |
Removes superseded snippets. |
docs/csharp/fundamentals/functional/pattern-matching.md |
Removes the superseded article. |
docs/csharp/fundamentals/expressions/index.md |
Adds a pattern-matching cross-link. |
docs/csharp/advanced-topics/interface-implementation/mixins-with-default-interface-methods.md |
Updates pattern-matching link. |
docs/csharp/advanced-topics/expression-trees/index.md |
Updates discard link. |
.openpublishing.redirection.csharp.json |
Preserves legacy article URLs. |
Review details
Suppressed comments (2)
docs/csharp/fundamentals/patterns/declaration-constant-var-patterns.md:51
- The preceding C# 15 note says
nullfollows union null-matching rules, but this sentence then claims that the pattern matches onlynull. For a union,nullcan also match an empty nullable union or a union whoseValueis null, so qualify this statement to exclude union-specific behavior.
The `null` constant pattern matches only `null`. It doesn't call a user-defined equality operator. That behavior makes the test reliable even when the value's type overloads `==`.
docs/csharp/fundamentals/patterns/pattern-matching.md:27
- This new overview states that untyped property, untyped positional, and list patterns are additional union exceptions, but the linked language-reference page still says only discard,
var, andnotare exceptions (language-reference/operators/patterns.md:384). Update the reference and the related union guidance together so readers don't get contradictory pattern semantics.
> Beginning with C# 15, which is currently in preview, patterns generally test a [union type's `Value`](../../language-reference/builtin-types/union.md#union-pattern-matching) rather than the union value itself. The discard, `var`, `not`, untyped property, untyped positional, and list patterns instead apply to the union value.
- Files reviewed: 56/64 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This is hopefully better.
Fixes #55926
Write the fundamentals articles on syntax and structure for pattern matching.
There are core files that moved and changed structure. Many of the other files only had links updated.
The articles that need a thorough review are:
varpatternsInternal previews
Toggle expand/collapse
Build report