I have an application that supports several types and versions of some devices. It can connect to these devices and receive various information.
Depending on the type of device, I have (among other things) a class that can contain various properties. Some properties are common to all devices, some of them are unique to a particular device.
This data is serialized in xml.
What would be the preferred way to implement a class that will support future properties in future versions of these devices, as well as be backward compatible with previous versions of applications?
I can think of several ways, but I do not consider them insignificant:
- Use a collection of name-value pairs:
- pros : good backward compatibility (both xml and previous versions of my application) and extensibility,
- cons : no type security, no intellisense, implementation of custom XML serialization required (for processing various objects
value)
- Create a class of derived properties for each new device:
- pros : security type
- cons : do you need to use
XmlIncludeeither custom serialization to deserialize derived classes, without backward compatibility with the previous xml schema (although, while implementing custom serialization, could I skip unknown properties?), a listing is required to access the properties in the derived classes.
- Another way to do this?
I am using C # by the way.