C# : xml serialization of nodes with cyclic links

社会主义新天地 提交于 2019-12-05 07:05:58

For xml, I would go with the id approach (changing the DTO model such that it isn't cyclic).

Note that DataContractSerializer can support cyclic object graphs automatically by passing in true for the preserveObjectReferences option in the overloaded constructors; it won't be quite as simple as XmlSerializer output, but it will still be readable.

If you switch to WCF DataContractSerializer, you can preserve the Object References (in 3.5 SP 1 and later)

[DataContract(IsReference=true)]

Sowmy has a good write up here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!