Skip to content

Complete pattern matching: deconstruction and object-behavior tutorial - #56286

Draft
BillWagner wants to merge 4 commits into
dotnet:mainfrom
BillWagner:patterns-fundamentals
Draft

BillWagner wants to merge 4 commits into
dotnet:mainfrom
BillWagner:patterns-fundamentals

Conversation

@BillWagner

@BillWagner BillWagner commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Closes #55928 (Everyday C# Phase F, PR 21).

  • Revise and move fundamentals/functional/deconstruct.md to fundamentals/patterns/deconstruct.md, covering tuples, records, custom Deconstruct methods/overloads, extension-method deconstruction, and mixed declared/var/discard deconstructions. Consolidate its samples into the shared patterns snippets project.
  • Migrate tutorials/patterns-objects.md (canal-lock state-machine tutorial) to fundamentals/tutorials/pattern-matching.md, with its own snippet project.
  • Relocate the pre-existing "type-driven and data-driven algorithms" (toll-calculator) tutorial to fundamentals/tutorials/advanced/pattern-matching.md to free the fundamentals/tutorials/pattern-matching.md slug for the migrated tutorial; update its snippet source paths and inbound links.
  • Update toc.yml: add the deconstruct article and both tutorials in their new locations; remove the now-empty Functional techniques node and the legacy top-level "Explore patterns in objects" entry.
  • Add/update redirects for every moved path, including the former functional/deconstruct.md and tutorials/patterns-objects.md locations, and the top-level docs/csharp/deconstruct.md redirect target.
  • Fix inbound links across the guide (types/tuples.md, discards.md, property-positional-patterns.md, language-reference pages, misc/ compiler-message pages, tour-of-csharp) that referenced the old functional/ and top-level tutorial paths.

Completes Pattern matching (§11) with no remaining planned core gaps; all moved paths have redirects, and no former functional/ deconstruction path breaks.


Internal previews

Toggle expand/collapse
File Preview link
.openpublishing.redirection.csharp.json Learn preview
docs/core/whats-new/dotnet-core-3-0.md Learn preview
docs/csharp/advanced-topics/expression-trees/index.md Learn preview
docs/csharp/fundamentals/expressions/operators.md Learn preview
docs/csharp/fundamentals/patterns/deconstruct.md Learn preview
docs/csharp/fundamentals/patterns/discards.md Learn preview
docs/csharp/fundamentals/patterns/property-positional-patterns.md Learn preview
docs/csharp/fundamentals/patterns/snippets/patterns/DeconstructSamples.cs Learn preview
docs/csharp/fundamentals/tutorials/build-algorithms-using-pattern-matching.md Learn preview
docs/csharp/fundamentals/tutorials/pattern-matching-basics.md Learn preview
docs/csharp/fundamentals/tutorials/snippets/pattern-matching-objects/CanalLock.cs Learn preview
docs/csharp/fundamentals/tutorials/snippets/pattern-matching-objects/InterimSteps.cs Learn preview
docs/csharp/fundamentals/tutorials/snippets/pattern-matching-objects/Program.cs Learn preview
docs/csharp/fundamentals/types/tuples.md Learn preview
docs/csharp/language-reference/builtin-types/value-tuples.md Learn preview
docs/csharp/language-reference/compiler-messages/deconstruction-errors.md Learn preview
docs/csharp/language-reference/compiler-messages/tuple-errors.md Learn preview
docs/csharp/language-reference/keywords/method-parameters.md Learn preview
docs/csharp/language-reference/operators/is.md Learn preview
docs/csharp/language-reference/operators/patterns.md Learn preview
docs/csharp/language-reference/operators/switch-expression.md Learn preview
docs/csharp/misc/cs0819.md Learn preview
docs/csharp/toc.yml Learn preview
docs/csharp/tour-of-csharp/index.yml Learn preview
docs/csharp/tour-of-csharp/tutorials/pattern-matching.md Learn preview

Build report

Closes dotnet#55928 (Everyday C# Phase F, PR 21).

- Revise and move fundamentals/functional/deconstruct.md to
  fundamentals/patterns/deconstruct.md, covering tuples, records,
  custom Deconstruct methods/overloads, extension-method
  deconstruction, and mixed declared/var/discard deconstructions.
  Consolidate its samples into the shared patterns snippets project.
- Migrate tutorials/patterns-objects.md (canal-lock state-machine
  tutorial) to fundamentals/tutorials/pattern-matching.md, with its
  own snippet project.
- Relocate the pre-existing "type-driven and data-driven algorithms"
  (toll-calculator) tutorial to
  fundamentals/tutorials/advanced/pattern-matching.md to free the
  fundamentals/tutorials/pattern-matching.md slug for the migrated
  tutorial; update its snippet source paths and inbound links.
- Update toc.yml: add the deconstruct article and both tutorials in
  their new locations; remove the now-empty Functional techniques
  node and the legacy top-level "Explore patterns in objects" entry.
- Add/update redirects for every moved path, including the former
  functional/deconstruct.md and tutorials/patterns-objects.md
  locations, and the top-level docs/csharp/deconstruct.md redirect
  target.
- Fix inbound links across the guide (types/tuples.md, discards.md,
  property-positional-patterns.md, language-reference pages, misc/
  compiler-message pages, tour-of-csharp) that referenced the old
  functional/ and top-level tutorial paths.

Completes Pattern matching (§11) with no remaining planned core
gaps; all moved paths have redirects, and no former functional/
deconstruction path breaks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

The moved advanced tutorial contains broken relative references, and stale routing sends readers to the wrong tutorial.

Review effort: Balanced
Findings: 5 Medium severity

Open (5)
What changed in this PR

This PR reorganizes and completes the C# pattern-matching documentation.

Changes:

  • Adds expanded deconstruction guidance and consolidated samples.
  • Moves the canal-lock and toll-calculator tutorials into Fundamentals.
  • Updates navigation, links, redirects, and obsolete files.
File Description
.openpublishing.redirection.csharp.json Updates redirects for moved content.
docs/​csharp/​advanced-topics/​expression-trees/​index.md Updates the deconstruction link.
docs/​csharp/​fundamentals/​expressions/​operators.md Updates the deconstruction link.
docs/​csharp/​fundamentals/​functional/​deconstruct.md Removes the superseded article.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​Program.cs Removes legacy snippet scaffolding.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​class-discard1.cs Removes a legacy discard sample.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-class1.cs Removes a legacy class sample.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-class2.cs Removes legacy overload samples.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-extension1.cs Removes a legacy extension sample.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-kvp.cs Removes a legacy dictionary sample.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple1.cs Removes legacy tuple sample 1.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple2.cs Removes legacy tuple sample 2.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple3.cs Removes legacy tuple sample 3.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple4.cs Removes legacy tuple sample 4.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple5.cs Removes legacy tuple sample 5.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruct-tuple6.cs Removes legacy tuple sample 6.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​deconstruction.csproj Removes the legacy snippet project.
docs/​csharp/​fundamentals/​functional/​snippets/​deconstructing-tuples/​discard-tuple1.cs Removes the legacy tuple-discard sample.
docs/​csharp/​fundamentals/​patterns/​deconstruct.md Adds comprehensive deconstruction guidance.
docs/​csharp/​fundamentals/​patterns/​discards.md Updates deconstruction links.
docs/​csharp/​fundamentals/​patterns/​property-positional-patterns.md Updates deconstruction links.
docs/​csharp/​fundamentals/​patterns/​snippets/​patterns/​DeconstructSamples.cs Adds consolidated deconstruction samples.
docs/​csharp/​fundamentals/​patterns/​snippets/​patterns/​Program.cs Runs the new samples.
docs/​csharp/​fundamentals/​tutorials/​advanced/​pattern-matching.md Relocates the toll-calculator tutorial.
docs/​csharp/​fundamentals/​tutorials/​pattern-matching.md Adds the canal-lock tutorial.
docs/​csharp/​fundamentals/​tutorials/​snippets/​pattern-matching-objects/​CanalLock.cs Updates the sample namespace.
docs/​csharp/​fundamentals/​tutorials/​snippets/​pattern-matching-objects/​InterimSteps.cs Adds tutorial progression samples.
docs/​csharp/​fundamentals/​tutorials/​snippets/​pattern-matching-objects/​Program.cs Updates the sample namespace.
docs/​csharp/​fundamentals/​tutorials/​snippets/​pattern-matching-objects/​pattern-matching-objects.csproj Updates the root namespace.
docs/​csharp/​fundamentals/​types/​tuples.md Updates the deconstruction link.
docs/​csharp/​language-reference/​builtin-types/​value-tuples.md Updates the deconstruction link.
docs/​csharp/​language-reference/​compiler-messages/​deconstruction-errors.md Updates article links and anchors.
docs/​csharp/​language-reference/​compiler-messages/​tuple-errors.md Updates the deconstruction link.
docs/​csharp/​language-reference/​keywords/​method-parameters.md Updates the deconstruction link.
docs/​csharp/​language-reference/​operators/​is.md Updates the advanced tutorial link.
docs/​csharp/​language-reference/​operators/​patterns.md Updates tutorial and deconstruction links.
docs/​csharp/​language-reference/​operators/​switch-expression.md Updates the advanced tutorial link.
docs/​csharp/​misc/​cs0819.md Updates deconstruction links and anchors.
docs/​csharp/​toc.yml Reorganizes pattern articles and tutorials.
docs/​csharp/​tour-of-csharp/​tutorials/​pattern-matching.md Updates tutorial destinations.
docs/​csharp/​tutorials/​patterns-objects.md Removes the migrated tutorial.

Comment thread .openpublishing.redirection.csharp.json Outdated
Comment thread docs/csharp/fundamentals/tutorials/advanced/pattern-matching.md Outdated
Comment thread docs/csharp/fundamentals/tutorials/advanced/pattern-matching.md
Comment thread docs/csharp/fundamentals/tutorials/advanced/pattern-matching.md
Comment thread docs/csharp/fundamentals/tutorials/advanced/pattern-matching.md Outdated
BillWagner and others added 2 commits September 30, 2026 05:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…aming

- deconstruct.md: move property-vs-positional-pattern comparison out of
  the intro into a new "Deconstruction and pattern matching" section;
  define "arity" and "extension method" at first use; note that
  ambiguous overloads (including extension methods) are compiler
  errors; reframe system-type deconstruction as using the same
  mechanism, not a special case; add cross-links to positional
  records, property/positional patterns, and discards.
- Flatten both pattern-matching tutorials into fundamentals/tutorials/
  (remove the advanced/ subfolder): rename canal-lock tutorial to
  "Pattern matching basics" (pattern-matching-basics.md) and the
  toll-calculator tutorial to "Build algorithms using pattern
  matching" (build-algorithms-using-pattern-matching.md); update
  toc.yml, inbound links, and redirects accordingly.
- Apply readability fixes from Cray's review: ground "component",
  "out parameter", "positional record", and "extension method" before
  use; introduce "recursive pattern" at its first real occurrence
  instead of after the fact; clarify "exhaustive" and enum
  underlying-type wording; soften "logical"/"conjunctive" pattern
  terminology.
- Apply voice fixes from Harrison's review to the algorithms
  tutorial's opening framing paragraphs (clearer hook, plainer
  phrasing, less redundancy); remove the stray "assumes you're
  already familiar with C#/.NET" prerequisite line.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…and extension Deconstruct method

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

Complete the Pattern matching section with deconstruction coverage and the introductory tutorial

2 participants