在使用XmlSerializer使用.net什么限制(如果有的话)有哪些? [英] Using .Net what limitations (if any) are there in using the XmlSerializer?
问题描述
在使用XmlSerializer使用.net什么限制(如果有的话)有哪些? 例如,您可以序列图片到XML?
Using .Net what limitations (if any) are there in using the XmlSerializer? For example, can you serialize Images to XML?
推荐答案
XmlSerializer的有一些缺点。
The XmlSerializer has a few drawbacks.
- 必须知道所有的类型被序列化。通过界面,重新presents一个类型,序列化不知道你不能把它传递的东西。
- 在它不能做循环引用。
- 将序列化的同一个对象多次,如果对象图中多次引用。
- 在无法处理私有字段序列化。
我(愚蠢)写了我自己的序列来解决其中的一些问题。不要那样做;这是一个大量的工作,你会发现在这几个月的道路微妙的错误。我获得了在写我自己的序列化和格式化的唯一的事情是参与对象图序列化细节的更大的AP preciation。
I (stupidly) wrote my own serializer to get around some of these problems. Don't do that; it is a lot of work and you will find subtle bugs in it months down the road. The only thing I gained in writing my own serializer and formatter was a greater appreciation of the minutia involved in object graph serialization.
我找到了<一href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.netdatacontractserializer.aspx">NetDataContractSerializer当WCF出来。它所有的东西从上面的XmlSerializer没有做。它推动以类似的方式来XmlSerializer的序列化。一个装饰的各种属性或字段与属性告知序列化序列化是什么。我更换了自定义的串行我写的NetDataContractSerializer和非常满意的结果。我会极力推荐它。
I found the NetDataContractSerializer when WCF came out. It does all the stuff from above that XmlSerializer doesn't do. It drives the serialization in a similar fashion to the XmlSerializer. One decorates various properties or fields with attributes to inform the serializer what to serialize. I replaced the custom serializer I had written with the NetDataContractSerializer and was very happy with the results. I would highly recommend it.
这篇关于在使用XmlSerializer使用.net什么限制(如果有的话)有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!