I've implemented the ICloneable interface on a class of mine. I've
implemented it in two different ways both of which I feel should work
correctly, but only one does and I'd be curious to know why.
Working:
CallflowBase ret = null;
ret = this.MemberwiseClone() as CallflowBase;
ret.m_callflowName = this.m_callflowName;
/ * I'm resetting these values since I want to make sure the user
reintializes the cloned object before using it */
ret.m_initialized = false;
ret.m_deviceID = null;
ret.m_currentNode = null;
ret.m_asyncCommandProcessor = null;
ret.m_syncCommandProcessor = null;
if (this.m_rootNode != null)
{
ret.m_rootNode = this.m_rootNode.Clone() as INode;
}
NOT Working:
/* I figured it would be easier to just create a new instance since I
don't want to copy most of the members */
CallflowBase ret = new CallflowBase();
ret.m_callflowName = this.m_callflowName;
if (this.m_rootNode != null)
{
ret.m_rootNode = this.m_rootNode.Clone() as INode;
}
But it turns out that I'm not actually making a proper copy because I
end up pointing to the same object! Am I missing something obvious
here?
Thanks,
Dan