Question about CopyTo
by Scott Goodwin · in Torque X 2D · 02/15/2008 (11:00 pm) · 2 replies
I have a question about the correct way to implement CopyTo.
TorqueObjects are supposed to implement
The typical way of doing this is
What if the property is a reference type? Many classes in Torque X do this:
Is that right? Or should the referenced object by copied/cloned?
TorqueObjects are supposed to implement
public override void CopyTo(TorqueObject obj)to copy all public properties not marked with TorqueCloneIgnore attribute.
The typical way of doing this is
public override void CopyTo(TorqueObject obj)
{
base.CopyTo(obj);
TheClass obj2 = (TheClass)obj;
obj2.APublicProperty = APublicProperty;
}What if the property is a reference type? Many classes in Torque X do this:
public override void CopyTo(TorqueObject obj)
{
base.CopyTo(obj);
TheClass obj2 = (TheClass)obj;
obj2.APublic_ReferenceType_Property = APublic_ReferenceType_Property;
}Is that right? Or should the referenced object by copied/cloned?
About the author
#2
02/17/2008 (9:58 am)
My worry is about objects like GUIControl. I'm not exactly sure under what circumstances CopyTo gets called. But if it does, GUIControl.CopyTo copies the Style (reference) property. In the copied object if we were to do something like copiedObject.Style.IsOpaque = true; then the original (and all copies) sudden become opaque. Etc. I'm not sure this is what is wanted/expected.
Associate John Kanalakis
EnvyGames
John K.