ICloneable
does not define a spec for Clone()
and hence should not be implemented CS-R1104ICloneable
allows you to define methods that help in cloning the instances of your class. However, the specification does not define whether this clone operation is a shallow clone or a deep clone. If it is a deep clone, it may end up recursively referencing other objects in the object graph. Moreover, if a class implements ICloneable
, there may be a need for all its subtypes to implement it too. It is therefore recommended that you define your own method that aids in cloning.
class C : ICloneable
{
public object Clone()
{
// ...
}
}
class C
{
// Custom implementation
public object Clone()
{
// ...
}
}