views:

607

answers:

1

Hello there,

is it possible to dynamically set the datacontract's datamember attributes during runtime? Basically what I need is to read in serialized instances of a class which contained the DataMemeber attributes on two properties at the time of serialization, but the current 'version' does not longer have them but I need to migrate the old data set in these properties over to the new handling... sooo what I kind of need is to let the datacontract deserializer read the data including these 'old' values, and re-serialize them with the new config (as these properties' data is now stored and handled entirely differently).

Is this possible?

Cheers & thanks. -Jörg

A: 

You can specify types/known types - but not AFAIK member information. XmlSerializer is a bit more forgiving here... is there a chance the old types used xml attributes? (rather than data-contract attributes).

The other option is to provide an IDataContractSurrogate - but that isn't trivial.

Is there any chance you can decorate the class with the old attributes and the attributes (etc) for whatever new mechanism you're employing?

If the data is simple (i.e. only one or two types, in a simple relationship), you could use a parallel set of classes to deserialize, then copy the data (property-to-property etc) into the new data structure, and re-serialize. This gets harder as the complexity of the model increases.

Marc Gravell