I’m using the DataContractSerializer to serialize an objects properties and fields marked with DataMember attributes to xml.
Now a have another use case for the same class, where I need to serialize other properties and other fields.
Are there a way to add “another DataMemberAttribute” that can be used for my other serialization scenario?
No, basically.
If you want to use the existing
DataContractSerializer, you’ll have to maintain a second version of the DTO class and convert the data between them.Options if you are writing your own serialization code:
[DataMember]-style attribute(s) and interpret them at runtime in your own serialization codeIn reality, I expect the first will be the simplest choice.