我可以序列化匿名类型为XML? [英] Can I serialize Anonymous Types as xml?

查看:538
本文介绍了我可以序列化匿名类型为XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解,匿名类型标记为私有的编译器和属性是只读的。有没有办法将它们序列化到XML(不含反序列化)?它<一个href="http://stackoverflow.com/questions/331976/how-do-i-serialize-a-c-anonymous-type-to-a-json-string">works使用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?

推荐答案

对不起,你不能。 XML序列pretty的简单,只是序列化的公共读写类型。

Sorry, you cannot. The XML Serializer pretty much just serializes public read-write types.

请注意,我的反应是如何使用XML序列化。您可以与其他串行成功,特别是尝试用数据协定序列化。

Note that my response is about using the XML Serializer. You may succeed with other serializers, in particular, try it with the Data Contract Serializer.

这篇关于我可以序列化匿名类型为XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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