Comments (4)
Here is another example with HashSet. I guess they have the same root cause
using System;
using System.Collections.Generic;
using System.Linq;
using Force.DeepCloner;
namespace DeepClonerBug
{
internal class Program
{
static void Main(string[] args)
{
var org = new HashSet { new Location() };
if (!org.Contains(org.First())) throw new Exception();
var clone = org.DeepClone();
//uncomment to fix: clone = new HashSet<Location>(clone.ToList());
if (!clone.Contains(clone.First())) throw new Exception();
}
}
public class Location
{
}
}
from deepcloner.
You need to override GetHashCode
and Equals
methods for Location
class. It bad idea to add to dictionary objects without overriding these methods. It can cause issue in any situation
set.Add(new Location { Name = "A" });
set.Contains(new Location { Name = "A" }) // false
I know this issue but I do not found ways how to correctly bypass it. I can make some hotfixes for Dictionary
and HashSet
, but there are lot of another classes, with using these methods (e.g. ConcurrentDictionary
, or LINQ method Distinct
which creates specific internal HashSet).
from deepcloner.
OK, thank you for your reply. I can make it work with overriding GetHashCode and Equals.
Maybe this is not the right place to ask. I want to clone the same object multiple times, is there a way to speed up performance for this case?
from deepcloner.
I want to clone the same object multiple times
Code is optimized, so there are no sense to add special method for this (it will be complex with internal state). I'll think about this. May be I found way to do this method simple and self-descriptive.
from deepcloner.
Related Issues (20)
- This exception is occasionally thrown in clones βmust be writeable (Parameter 'left')β HOT 4
- Request for info (country of origin) HOT 4
- HashSet contains method return false after deep clone HOT 8
- Support for cloning child to parent type HOT 2
- the program crashed when i deepclone opencvsahrp Mat HOT 3
- How to only clone the common properties? HOT 4
- Latest change has not been published to NuGet HOT 1
- Why version 0.X? HOT 3
- Exception: An instance of the __ComObject type cannot be created unless the type has been obtained using GetTypeFromProgID or GetTypeFromCLSID. HOT 4
- program crashed when deepclone multidimensional zero-length array HOT 1
- Dependency on BinaryFormatter? HOT 1
- Possible Heap Corruption and Garbage Collection Interference... HOT 4
- When Object have navigation property, DeepClone throw exception. HOT 5
- Better error reporting HOT 1
- No stable cloning of `System.Drawing.Font` object HOT 6
- Memory corruption and program crash when cloning TaskCancelledException
- NHibernate Invalid cast exception
- Clone Action<T> delegate is incorrect
- Netstandard upgrade HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepcloner.