且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何反序列化为 List使用 XmlSerializer

更新时间:2023-09-09 11:29:46

添加这样的属性来保存组件列表:

Add a property like this to hold the list of Components:

[XmlArray()]
public List<Component> Components { get; set; }

抱歉我误读了.您想将其读入字符串集合.我只是在下面试过这个,它对你的样本有效.关键只是设置正确的xml序列化属性.

Sorry I misread that. You want to read it into a collection of strings. I just tried this below and it worked on your sample. The key is just to setup the correct xml serialization attributes.

public class ArsAction
{
    [XmlArray]
    [XmlArrayItem(ElementName="Component")]
    public List<string> Components { get; set; }
}