mijay / nclone Goto Github PK
View Code? Open in Web Editor NEWNClone - generic implementation of deep copy for arbitrary .NET objects
License: MIT License
NClone - generic implementation of deep copy for arbitrary .NET objects
License: MIT License
I have a use case where I need to clone something that has a field like:
Dictionary<string, <Dictionary<string, string>>
That crazyness is basically a way to get a known 2-level json object to deserialize.
I noticed the inner dictionary was only a shallow copy. If this is not meant to be supported than this isn't an issue, but I thought I'd put this here in case anyone else runs into it.
If I clone a list where some items are value equals, but not reference equals, I end up with a list where some of the cloned items are actually the same object. This leads to unexpected changes when modifying objects that were originally different references before cloning.
This should not happen by default.
This library is exactly what many people working with EF are looking for, unfortunately there's a missing feature that makes it unusable, the capability to clone graph of objects with circular references.
EF Graphs are by default CircularReference Graphs because into the Parent table there is a Collection of Cildren and into the Child table there is the Reference of the Parent.
I tried to fork and to work on your code to add this feature but I'm not enough skilled to do with an acceptable level of quality so I'm asking you if you could work on it to add this functionality.
I'm also available to pay you something for your effort.
Thanks again!
mM
NClone appears to have a concurrency bug.
I recently modified our test suite to run more tests in parallel, and since then I've been getting intermittent failures when cloning. This is using version 1.1.1 from Nuget.
So for example, i I have:
private Currency _depositAmount = NClone.Clone.ObjectGraph(Currency.Empty);
Then I will sometimes see the exception:
Result Message:
Test method threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
Result StackTrace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at NClone.ReplicationStrategies.ReplicationStrategyFactory.StrategyForType(Type type)
at NClone.ObjectReplication.ReplicationContext.Replicate(Object source)
at NClone.ObjectReplication.ObjectReplicator.Replicate[T](T source)
at DomainModel.Entities.Deposit.ctor()
From the stacktrace, I suspect this bug is occurring because the replication strategy is caching per type, but using the non-threadsafe System.Collections.Generic.Dictionary
. I suspect replacing with a thread-safe collection would resolve the issue.
The Clone class documentation states that it does not deep clone structures. If that's the case it's a problem because a struct can contain references to mutable objects. When someone updates those objects, your original graph will also change.
When trying to compile NClone in VS 2013, pulled from Github, I keep getting:
Warning 1 The referenced project '..\mijay.Utils\mijay.Utils.csproj' does not exist. NClone.Tests
Warning 2 The referenced project '..\mijay.Utils\mijay.Utils.csproj' does not exist. NClone.Benchmarks
Warning 3 The referenced project '..\mijay.Utils\mijay.Utils.csproj' does not exist. NClone
Warning 4 The referenced project '..\mijay.Utils\mijay.Utils.csproj' does not exist. NClone
Warning 5 The referenced component 'mijay.Utils' could not be found. NClone
How can I get around this? What is contained in "mijay.Utils" that is needed inside the NClone project(s) ? Couldn't that be included directly into NClone??
We'd like to use it within ASP.NET Core project.
Is it ever portable to .NET Core?
I understand it's by design but I don't get the point why. We have a case when a default constructor must be called, otherwise we end up with a replicated object in an invalid state.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.