I'm currently working on a c# app that is communicating with a node.js server via JSON. I'm using Json.net to do the deserialisation.
My problem is that the JSON messages are of various types (it's not known which until the message comes in), and I need to deserialise to the correct type depending on which type of message it is.
Is there an elegant approach to this? Possible (non-ideal) solutions that have occurred to me include some kind of 'all encompasing' message DTO type which any message can be deserialised to (not nice); or some kind of 'message in a message' where a message type identifier is deserialsed, and then a sub-message is then deserialsed to a specific type, but I feel there must be a better way.
I'm limited to .Net 3.5, so can't use the dynamic
keyword.
Thank you