Complete pattern matching: deconstruction and object-behavior tutorial - #56286
Draft
BillWagner wants to merge 4 commits into
Draft
BillWagner wants to merge 4 commits into
BillWagner wants to merge 4 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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
Open (5)
Update legacy redirect to moved pattern-matching tutorial · New Update stale inbound link to moved toll-calculator tutorial · New Fix prerequisites include path after tutorial move · New Fix language-reference links for deeper tutorial location · New Fix snippet include path after tutorial move · New
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. |
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>
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.

Closes #55928 (Everyday C# Phase F, PR 21).
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
Build report