29
An easy way to clone an object is writing it into a stream and read it again:
public object Clone()
{
object clonedObject = null;
BinaryFormatter formatter = new BinaryFormatter();
using (Stream stream = new MemoryStream())
{
formatter.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
clonedObject = formatter.Deserialize(stream);
}
return clonedObject;
}
But be aware of, that this can cause problems with so called aggregate object.