是否有可能与循环引用执行序列化? [英] Is It possible to perform serialization with circular references?

查看:142
本文介绍了是否有可能与循环引用执行序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的实体类(C#编写)遵循父子模型,其中每个子对象必须在它保持其家长参考parent属性。



这Parent属性导致在对象的序列由于循环引用的问题。



我不能删除提及父母,无论是我可以将其标记XmlIgnore(因为我需要读它回来时,我反序列化XML)



在此?


解决方案<任何想法/ DIV>

XML序列化不支持循环引用,你需要排除从序列使用 XmlIgnore 属性parent属性。请参见了这篇博客文章的方式来维护,当你反序列化的关系。



另外,你可以使用的DataContractSerializer 而不是 XmlSerializer的。它支持循环引用,但不提供对XML模式...


多控制

So, my entity class (written in C#) follows a parent child model where every child object must have a Parent property in which it keeps reference of its Parent.

This Parent property causes issues in serialization of the Object due to circular references.

I can't remove the reference to parent, neither I can mark it XmlIgnore (since I need to read it back when I deserialize the XML)

Any ideas on this?

解决方案

XML serialization doesn't support circular references, you need to exclude the parent property from the serialization using the XmlIgnore attribute. See this blog post for a way to maintain the relationship when you deserialize.

Alternatively, you could use DataContractSerializer instead of XmlSerializer. It supports circular references, but doesn't provide much control over the XML schema...

这篇关于是否有可能与循环引用执行序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆