Cloning a class

Monkey Forums/Monkey Programming/Cloning a class

svero(Posted 2011) [#1]
Is there an easy to way clone an instance of an object into another without manually copying every field one by one?


AdamRedwoods(Posted 2011) [#2]
Good question.
http://en.wikipedia.org/wiki/Object_copy

My guess is at the moment, no, you would have to copy field by field.


Tibit(Posted 2011) [#3]
Just for reference,

Two common ways to do it is to either create a Copy() method, or to add a Overload to the Constructor that takes an object of the same sort.

Local copiedCar:Car = car.Copy

or

Local copiedCar:Car = new Car( car )