C
Charles
I am writing and reading XML on a TCP connection. Once I have sent an XML
message I have to wait for a reply, which could be in one of several forms.
All the possible replys have a basic set of attributes in common, but then
might have additional information.
I have a base class for the common attributes and derived classes for the
variants.
What I would like to do is deserialise the reply, polymorphically, to an
object of the derived class but I'm not sure how to do that. I have tried
deserialising as a generic reply in order to test what type of object I
have, but the deserialise call fails with an error in the stream. I can
understand why it fails, because there are attributes in the stream that do
not exist in the base class, but that doesn't get me any closer to the
solution.
If I know what derived class the reply is I can explicitly deserialise as
that object type, but in normal operation I don't know what object type I am
receiveing until I have deserialised it, if that makes sense.
Does anyone have an idea how this might be done?
TIA
Charles
message I have to wait for a reply, which could be in one of several forms.
All the possible replys have a basic set of attributes in common, but then
might have additional information.
I have a base class for the common attributes and derived classes for the
variants.
What I would like to do is deserialise the reply, polymorphically, to an
object of the derived class but I'm not sure how to do that. I have tried
deserialising as a generic reply in order to test what type of object I
have, but the deserialise call fails with an error in the stream. I can
understand why it fails, because there are attributes in the stream that do
not exist in the base class, but that doesn't get me any closer to the
solution.
If I know what derived class the reply is I can explicitly deserialise as
that object type, but in normal operation I don't know what object type I am
receiveing until I have deserialised it, if that makes sense.
Does anyone have an idea how this might be done?
TIA
Charles