I use the following method - accepts any object whose class is marked
'serializable'. If you want a shallow copy, which is what I usually
use, mark the object references of the class you're copying as
non-serializable and copy the references separately after calling
CloneObject:
internal static object CloneObject(object oObject)
{
//returns a separate object with all serializable
//properties set to those of oObject (the object class
//must have the "Serializable" attribute)
System.IO.MemoryStream oStream = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
oFormatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
oFormatter.Serialize(oStream, oObject);
oStream.Seek(0, System.IO.SeekOrigin.Begin);
return oFormatter.Deserialize(oStream);
}