One of best practices is to implement ICloneable on our objects. However most os times it is not used or because it comes from db or they are created as news.. It depends on many variables.

What happens is that most of time it is not implemented (since I left Uminhos university I don’ t really remember how many times I have done it…. but there was a little few).

So I pretend on doing it! Because of that I googled a little and I found a nice class to extend objects so they are cloneable:

[csharp]
public static class ExtensionMethods
{
public static T DeepCopy(this T oSource)
{
T oClone;
DataContractSerializer dcs = new DataContractSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream())
{
dcs.WriteObject(ms, oSource);
ms.Position = 0;
oClone = (T)dcs.ReadObject(ms);
}

return oClone;
}
}
[/csharp]
my source was Jason Barkes on his blog.