XML序列化结构抱歉标题没有说的更具体,只能举个例子来说明。我正在尝试构建一个序列化为以下XML的类我的C#是:[XmlRoot]publicCustomizeCustomize{get;放;}和publicclassCustomize{publicListContent{get;放;}公共列表命令{get;放;然而,这会产生(它应该)如下:是否有一些xml序列化属性可以帮助实现我想要的xml,或者我是否必须找到另一种编写类的方法?使用XmlElementAttribute标记集合属性。publicclassCustomize{[XmlElement("Content")]publicListContent{get;放;}[XmlElement("Command")]publicListCommand{get;放;}}快速测试代码:varitem=newCustomize(){Content=newList{newContent(),newContent()},Command=newList{newCommand(),newCommand(),newCommand()}};字符串结果;使用(varwriter=newStringWriter()){varserializer=newXmlSerializer(typeof(Customize));serializer.Serialize(writer,item);结果=writer.ToString();}打印:以上就是C#学习教程:XML序列化结构分享的全部内容,如果对你有用,还需要了解更多C#学习教程,希望大家多加关注——publicclassCustomize{[XmlElement("Content")]publicListContent{get;放;}[XmlElement("Command")]publicListCommand{get;放;}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
