Skip to content

Refuse a DeepCloneFrom between OrderedDictionaries or ConcurrentDictionaries with different comparers [patch] - #145

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/143-deepclonefrom-ordered-concurrent-comparer
Nov 13, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/143-deepclonefrom-ordered-concurrent-comparer

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #143

What changed

  • EnsureSameComparer<TKey, TValue> only checked Dictionary, SortedDictionary and SortedList. A case-insensitive OrderedDictionary or ConcurrentDictionary source could be copied into an ordinal destination with no error, and lookups that worked on the source then missed on the clone. It now checks:
    • OrderedDictionary<TKey, TValue>, guarded by #if NET9_0_OR_GREATER
    • ConcurrentDictionary<TKey, TValue>. Its comparer is read through the existing ConcurrentComparer<TKey, TValue>.Of, so this also works on the netstandard targets.
  • The list of guarded kinds is updated in the DeepCloneFrom XML doc, the README and CLAUDE.md.
  • Not done: the triage's optional idea of a generic check for any IDictionary whose comparer can be read. This PR is scoped to the two kinds the issue names.

Tests

  • Added to DeepCloneFromComparerTests:
    • for each of the two kinds, a mismatched comparer throws ArgumentException and leaves dest unchanged
    • for both kinds, a matching case-insensitive comparer clones normally
  • With the library change reverted, the two mismatch tests fail. With it, they pass.
  • The full suite passes: 164 tests on net10.0. The library builds with no warnings for net10.0, net9.0, net8.0, netstandard2.0 and netstandard2.1.

Generated by Claude Code

…entDictionaries with different comparers

EnsureSameComparer only checked Dictionary, SortedDictionary and SortedList,
so a case-insensitive OrderedDictionary or ConcurrentDictionary source was
copied into an ordinal destination without error, and lookups that worked on
the source missed on the clone. Both kinds are now checked; the concurrent
comparer is read through ConcurrentComparer.Of so the netstandard builds work.

Fixes #143

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

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants