|
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 | """ |
|---|
| 3 | One way to deep copy an object is to serialize it and the deserialize it. |
|---|
| 4 | |
|---|
| 5 | See also: |
|---|
| 6 | http://www.codeproject.com/KB/tips/SerializedObjectCloner.aspx |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | class 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) |
|---|