DeepCopy: dependency-free reflection-based deep clone (11.0.0)#6
Merged
Conversation
Replace the Newtonsoft JSON round-trip with a recursive reflection clone: - copies all instance fields, including private and inherited ones - preserves shared-reference identity and handles reference cycles via a reference-equality visited map - no serializable/parameterless-ctor requirement - strings/known immutables reused; delegates and Type copied by reference; pointer fields skipped; arrays (incl. multi-dimensional) deep-cloned - FieldInfo cached per type; GetUninitializedObject via RuntimeHelpers on net8 and FormatterServices on netstandard2.0 Removes the Newtonsoft.Json package dependency and the JsonSerializerSettings overload (breaking -> 11.0.0). StandardInterfaces is now the only dependency. Added tests for nested/collection cloning, private fields, shared references, cycles, and arrays. 182/182 passing, clean build on both TFMs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Cover value types/immutables, nullables, inherited private fields, struct-with-reference, delegate-by-reference, primitive/empty/multi- dimensional/jagged arrays, Dictionary, self-cycles, and shared-reference identity within a collection. 195/195 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Replaces the Newtonsoft JSON round-trip in
DeepCopywith a true reflection-based deep clone, and removes the Newtonsoft.Json dependency entirely (it was the only consumer).StandardInterfacesis now the package's only dependency.Why
The old
DeepCopyserialized to JSON and back: it pulled in a heavy dependency, was slow, only copied public properties, required JSON-friendly types, and broke on reference cycles.New behavior
GetUninitializedObject).Typeare copied by reference; pointer fields are skipped; arrays (including multi-dimensional) are deep-cloned.FieldInfocached per type;RuntimeHelpers.GetUninitializedObjecton net8,FormatterServiceson netstandard2.0.Breaking change → 11.0.0
DeepCopy<T>(this T, JsonSerializerSettings)overload is removed; the new signature isDeepCopy<T>(this T).Tests
Added coverage for nested/collection cloning, private fields, shared-reference identity, reference cycles, and arrays. 182/182 passing, clean build (0 warnings) on both TFMs. Verified the packed nuspec lists only
StandardInterfaces.🤖 Generated with Claude Code