How to deeply clone related objects in C #?

What is the best way to deeply clone an interconnected set of objects? Example:

class A {
    B theB; // optional
    // ...
}

class B {
    A theA; // optional
    // ...
}

class Container {
    A[] a;
    B[] b;
}

The obvious thing to do is walk around the facilities and deeply clone everything that I come to him. This creates a problem, however, if I clone Awhich contains B, and what is Balso in Container, it Bwill be cloned twice after I clone Container.

The next logical step is to create Dictionaryand search for each object before I clone it. It looks like it could be a slow and indecent decision.

Any thoughts?

+5
6

, ( -). , hashmap , .

+2

- , . , object.GetHashCode() . , ( 10 100 ).

+2

, #, , , - , - . , .

+2

-, , .

0

, , - , . , .

0

, . .NET, DataContractSerializer, . , , .

0

All Articles