我可以将匿名类型序列化为 xml 吗? [英] Can I serialize Anonymous Types as xml?
本文介绍了我可以将匿名类型序列化为 xml 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道匿名类型被编译器标记为私有并且属性是只读的.有没有办法将它们序列化为 xml(无需反序列化)?它适用于 JSON,如何我可以用 XML 来做吗?
I understood that anonymous types are marked private by the compiler and the properties are read-only. Is there a way to serialize them to xml (without deserialize) ? It works with JSON, how can I do it with XML?
推荐答案
使用 XmlSerializer
或 DataContractSerializer
都无法完成.它可以通过手动编写的代码来完成,如下所示(我无法评论代码是否全面足以处理所有类型 - 但这是一个非常好的开始).
It can't be accomplished using XmlSerializer
nor DataContractSerializer
. It can be done by a manually written code, as demonstrated below (I can't comment as to whether the code is comprehensive enough to handle all types - but it's a very good start).
这篇关于我可以将匿名类型序列化为 xml 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文