I managed to get a object copying function done for simple types, but when you add recursion, and tlists, it just got too complicated. Here's a start if someone wants to try.. It crashes without any error message so it's difficult to debug.
Function Copy:Object(Obj:Object)
Local id:TTypeId = TTypeId.ForObject(Obj)
Local NewObj:Object = id.NewObject()
For Local fld:TField = EachIn id.EnumFields()
Local nf:TField = GetField(NewObj,fld.Name())
Local ti:TTypeId = nf.TypeId()
If ti.Name() = "TList" Then
'...
ElseIf ti = ByteTypeId Or ti = ShortTypeId Or ti = IntTypeId Or ti = LongTypeId ..
Or ti = FloatTypeId Or ti = DoubleTypeId Or ti = StringTypeId Or ti = ObjectTypeId ..
Or ti = ArrayTypeId Or ti.Fields().Count() = 1 Then
nf.Set(NewObj,fld.Get(Obj))
Print nf.Name()
Else
Print nf.Name()
nf.Set(NewObj,Copy(fld.Get(Obj)))
EndIf
Next
Return NewObj
End Function
Function GetField:TField(Obj:Object,FieldName:String)
Local id:TTypeId = TTypeId.ForObject(Obj)
For Local fld:TField = EachIn id.EnumFields()
If fld.Name() = FieldName Then Return fld
Next
Return Null
End Function
|