This is an extension method that operates on different types of objects and creates its own copy.
This method is generic so it can clone different types of objects
public static T Clone<T>(this T source)
{
var dcs = new DataContractSerializer(typeof(T));
using (var ms = new System.IO.MemoryStream())
{
dcs.WriteObject(ms, source);
ms.Seek(0, System.IO.SeekOrigin.Begin);
return (T)dcs.ReadObject(ms);
}
}
If you are not familiar with extension method then please refer to my previous blog
0 Comment(s)