public static object Clone(object obj)
{
return Clone(obj, true);
}
public static object Clone(object obj, bool serialize)
{
MemoryStream ms = new MemoryStream();
if (serialize)
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, obj);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
return bf.Deserialize(ms);
}
else
{
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
return ms;
}
}