Giter Club home page Giter Club logo

Comments (4)

kakkamstrup avatar kakkamstrup commented on July 19, 2024

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.

force-net avatar force-net commented on July 19, 2024

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.

kakkamstrup avatar kakkamstrup commented on July 19, 2024

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.

force-net avatar force-net commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.