Why should I use DataContract Serializer while I have XML/Binary serializer?
Can anyone 开发者_开发技巧please elabortae me the reasons why should I use Data Contract Serializer while we have XML/Binary serializer already there in .Net ?
This is a site i found when i was looking into the same issue. You should check this out
Quoting from the same link mentioned above:
Advantages of DataContractSerializer over XMLSerializer
- Opt-in rather than opt-out properties to serialize.
- Because it is opt in you can serialize not only properties, but also fields. You can even serialize non-public members such as private or protected members. And you dont need a set on a property either (however without a setter you can serialize, but not deserialize)
- Is about 10% faster than XmlSerializer to serialize the data because since you don’t have full control over how it is serialize, there is a lot that can be done to optimize the serialization/deserialization process.
- Can understand the SerializableAttribute and know that it needs to be serialized
- More options and control over KnownTypes
Hope it helps!
One more HUGE advantage; DataContract serialization allows for interop between any two classes that implement the same DataContract. This is what allows WCF to generate the data classes for you automatically when you reference a WCF service. You can also "hack" this process by referencing a published DataContract in a new user-developed class (or two or three); You can then transfer data between instances of these classes, and any other new ones you create, via serialization. This is also possible but much more difficult with XML serialization, and impossible with binary serialization.
精彩评论