Wiki

root/cobra/trunk/HowTo/400-DeepCopyObjects.cobra

Revision 2338, 434 bytes (checked in by Chuck.Esterbrook, 2 years ago)

Code cleanup.

  • Property svn:eol-style set to native
Line 
1# .skip.
2"""
3One way to deep copy an object is to serialize it and the deserialize it.
4
5See also:
6http://www.codeproject.com/KB/tips/SerializedObjectCloner.aspx
7"""
8
9
10class ObjectCopier
11
12    def copy(obj) is shared
13        require
14            obj.typeOf.isSerializable
15        test
16            pass
17        body
18            try
19                stream = MemoryStream()
20                Serializer.serialize(stream, obj)
21                stream.close
22            catch exc as Exception
23                throw InvalidOperationException('', exc)
Note: See TracBrowser for help on using the browser.