views:

14

answers:

0

Actually i have a class like this

[DataContract]
public class Item : IExtensibleDataObject
{
    [Browsable(false)]
    public virtual ExtensionDataObject ExtensionData { get; set; }

    [DataMember]
    public string ID { get; set; }

    [DataMember]
    public string Name { get; set; }

    public Item()
        : this(String.Empty, String.Empty)
    { }

    public Item(string id, string name)
    {
        ID = id ?? String.Empty;
        Name = name ?? String.Empty;
    }
}

You can easily serialize and deserialize it. But now comes the hard part:

I have to rename the property Name to FullName and every new xml serialized file should come out with the FullName while it is still possible to read in the old files.

To get the new property name out into a new file is quite easy. Just rename the property and you're done.

For compatibility i would mark the new property name with [DataMember(Name="Name")] but in this case if i write this class back into a file i got the old name written.

So exists there something in the DataContract where i can mark my property FullName maybe twice like

[DataMember(Name="Name")]
[DataMember]
public string FullName { get; set}

or is there any other mechanism how i can show that both values can be written into this, but only one will come out on writing back?

The only way i can imagine of would be to create a class LegacyItem which has no functions or something like this, but fulfills the old DataContract. Additionally some kind of implicit/explicit operator to convert my LegacyItem into an Item. Last but not least on deserializing i have to make some tests (maybe just a simple try/catch) to find out what class i should tell the DataContractSerializer to read in the file.

So even if this approach would be possible it sounds a little bit overcomplicated for this task and i'm wondering if there isn't something already available within the framework that would make this task a little bit easier.