Search code examples
c#serializationdatacontractserializer

DataContractSerializer Best Practices?


Edit -- I'll try to make my question more to the point

I am working with the DataContractSerializer. I noticed that when I instance the serializer, I can specify the Namespace and the Name. Is there any guidance out there (or maybe a best-practice) to describe when I might want to take control of the name and namespace, and what I might want to use for the values?

I was tempted to use the namespace and class name of the class that I am serializing deserializing. Is that a good or bad practice?


Solution

  • DataContractSerialializer is a contract-based serializer, so forwards compatibility shouldn't a huge problem as long as you are adding - and if you do want to rename, you can hide that by adding the old name via attributes. As such, I would say "keep it simple" - trying to get clever is the cause of many bugs.

    Re "What do you think?" (comments) - I think I'd rather use protobuf-net, but I'm somewhat biased :p