/// /// CloneClass is used to do a deep copy of any object. /// public class CloneClass { /// /// Initializes a new instance of the class. /// public CloneClass() { } /// /// Clones the specified object. /// /// The object to clone. /// Copy of the object. static public object Clone(object o) { object oCopy = null; //copies original object to stream then //deserializes that stream and returns the output //to create clone (copy) of object if (o == null) { return oCopy; } MemoryStream objMemStream = new MemoryStream(); BinaryFormatter objBinaryFormatter = new BinaryFormatter(); objBinaryFormatter.Serialize(objMemStream, o); objMemStream.Seek(0, SeekOrigin.Begin); oCopy = objBinaryFormatter.Deserialize(objMemStream); objMemStream.Close(); return(oCopy); } }