Skip to content

Show the explicit interface implementation in IDeepCloneable's remarks [patch] - #121

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/120-ideepcloneable-doc-example
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/120-ideepcloneable-doc-example

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #120

What changed

The <remarks> on IDeepCloneable.DeepClone() recommended public object DeepClone() => DeepClone();. Copied as written, that method calls itself until the process dies with an uncatchable stack overflow. Adding the strongly-typed Foo DeepClone() beside it fails instead with CS0111.

The remarks now show the explicit interface implementation that DeepCloneable<T> already uses:

public Foo DeepClone() => new() { Value = Value };
object IDeepCloneable.DeepClone() => DeepClone();

They also say why the other two forms fail.

Tests

IDeepCloneableDocumentationTests adds two tests:

  • DocumentedPattern_DeepCloneThroughInterface_ReturnsIndependentCopy implements IDeepCloneable exactly as documented and clones the type through the interface, so the pattern has to keep compiling and working.
  • Remarks_RecommendExplicitInterfaceImplementation reads the generated ktsu.DeepClone.xml and checks that the remarks show the explicit form and no longer give the self-recursive line as the example. It fails on main and passes with this change. I checked that by reverting the doc change and running it again.

Full suite: 68/68 passing on net10.0.


Generated by Claude Code

…s [patch]

The remarks recommended `public object DeepClone() => DeepClone();`,
which calls itself until the stack overflows, or fails with CS0111
once the strongly-typed DeepClone() is added beside it. Show the
explicit implementation DeepCloneable<T> already uses, and test that
the documented pattern clones through the interface.

Fixes #120

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2HqCSuHeAzmHzLkRc
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 950b98b into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/120-ideepcloneable-doc-example branch November 4, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDeepCloneable's IntelliSense example public object DeepClone() => DeepClone(); recurses forever (stack overflow) or doesn't compile

2 participants