Mark Smith Posted September 13, 2011 Report Share Posted September 13, 2011 I'm using the preserve run time class function to cast an incoming object like this. When I pass a parent class object into the EventMessage in, the current value of the parent class property is not preserved on the output. When I pass in a child class, the parent property is preserved. It's like a new default instance of the child class is created when I pass in the parent rather than a child class instance that has the incoming parent's properties preserved and defaults for the undefined child class properties. I expected the preserve run time class function to take the instance of the parent and "deep-copy" it a new child instance if the parent was on the wire. Apparently, I'm wrong about that. But I have to ask why this behavior? I can't think of why one wouldn't want to preserve the parent's properties as part of a cast (it seems that's a safe cast, like casting a 16 bit int to a 32). What am I missing? Thanks, Mark Quote Link to comment
Yair Posted September 13, 2011 Report Share Posted September 13, 2011 The PRTC primitive does not cast a parent to a child. It takes an existing child which is traveling on a parent wire and outputs it as a child wire. If the data in the left input is NOT a child, the primitive should return an error (and, as you've seen, a default child). Quote Link to comment
Mark Smith Posted September 13, 2011 Author Report Share Posted September 13, 2011 Yair, Thanks for the info - so I'm expecting more from the function that it's designed to do - I guess the function name explains it if I read carefully . Still, would it be useful to have a function that could convert (actually deep copy) a parent to a child and preserve the parent's data since it seems that would always be a safe thing to do? As far as I can tell, the To More Specific class VI would do the same thing as the Preserve Run Time Class - that is, fail and return a default instance of the child. Thanks, Mark Quote Link to comment
ned Posted September 13, 2011 Report Share Posted September 13, 2011 This has been asked before; there's no way to take a parent class and turn it into a child containing the same parent data as the input. See for example here: http://lavag.org/topic/13383-how-to-properly-cast-object-to-child-class/ Quote Link to comment
Mark Smith Posted September 13, 2011 Author Report Share Posted September 13, 2011 This has been asked before; there's no way to take a parent class and turn it into a child containing the same parent data as the input. See for example here: http://lavag.org/top...to-child-class/ I must be getting old... I participated in that thread so I should have remembered all this. Thanks, Mark Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.