xmlSerialize two lists of different objects

后端 未结 1 1384
天涯浪人
天涯浪人 2021-01-27 03:48

I need help to serialize two lists and write them in a xml file. The code I tried is

XmlSerializer xs = new XmlSerializer(typeof(List));
XmlSe         


        
相关标签:
1条回答
  • 2021-01-27 04:24

    Why not create a single class that would have both List types in it and serialize that class. like below.

    public class Combined
    {
     public List<OtherAction> otherActions{get; set;}
     public List<Action> actions{get; set;}
    }
    
    
    XmlSerializer xs = new XmlSerializer(typeof(List<Combined>));
    using (StreamWriter sw = new StreamWriter("CombinedActions.xml"))
    {
       xs.Serialize(sw, listCombinedActions);
    }
    
    0 讨论(0)
提交回复
热议问题