How deep should a deep copy go? / Is an object that contains value type still a reference type?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi all,

I'm implementing the Clone() method through the ICloneable interface
and don't quite know how deep I need to go for a deep copy.

Example:

class A: ICloneable
{
object _val;

//Val will always be a value type
A(object val)
{
_val = val;
}

object Clone()
{
//Don't know if I this is sufficient
return new A(_val);

//Or do I have to go
object newVal;

if(val.GetType() == typeof(bool))
{
newVal = (bool) val;
}
//....etc....//

return new A(newVal)
}
}

Thus do I have to cast the object back to a value type before returning
the cloned instance.

So I suppose the real question is: Is an object that contains value
type still a reference type?

Thanks,
Andre

.



Relevant Pages

  • Re: Newbie Q: Serialization and Me
    ... private / inner class and then use your serialization trick on *that* ... Dim bf As BinaryFormatter = New BinaryFormatter ... I have 2 objects and I want to make a deep copy of one into the ... I effectively want to clone an object into Me. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Copy of an object.
    ... There is an ICloneable interface which some types can choose to implement. ... What would it mean to clone a socket? ... > Thanks for such a quick response Adam. ... > be made of a .net object? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: super.clone() puzzlement
    ... this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. ... known as shallow clone. ...
    (comp.lang.java.programmer)
  • Re: Copy of an object.
    ... exporting MemberwiseClone isn't how shallow copies are done. ... deep - it's up to the implementing object to decide what to do. ... >> There is an ICloneable interface which some types can choose to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Deep Clones
    ... Clone() from the ICloneable interface: ... protected virutal void MakeDeep{/* replace shallow member copies ... shallow member copies with deep copies */} ... if a property deep deep down in one object references some ...
    (microsoft.public.dotnet.languages.csharp)