# .skip.
"""
One way to deep copy an object is to serialize it and the deserialize it.

There is a discussion about this found at:
http://www.wilmott.com/messageview.cfm?catid=10&threadid=39457

which this Cobra code is based on.
"""


class ObjectCopier

	def copy(obj as Object) is shared
		require
			obj.typeOf.isSerializable
		body
			try
				stream = MemoryStream()
				Serializer.serialize(stream, obj)
				stream.close






public static object CopyObject(object Instance)
{
                Type ActualType = Instance.GetType();
                if (ActualType.IsSerializable)
                {
                    try
                    {
                        MemoryStream Stream = new MemoryStream();

                        Serializer.Serialize(Stream, Instance);
                        Stream.Close();

                        return Serializer.Deserialize(Stream);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Could not copy object via serialization. Error was: " + e.Message);
                    }
                }
}