C#XmlSerialization属性类包含不同的元素

时间:2018-04-11 08:51:47

标签: c# xml properties xml-serialization xmlserializer

我目前正在研究WebService,并探讨了如何为以下用例定义属性类:

<Parent>
<Type1>int</Type1>
<Type2>string</Type2>
<Type3>Object</Type3>
<Type3>Object</Type3>
<Type3>Object</Type3>
<Type3>Object</Type3>
</Parent>

我的代码如下所示:

[XmlRoot]
class Parent
{
   [XmlElement]
   public int Type1 {get; set;}

   [XmlElement]
   public string Type2 {get; set;}

   [XmlArray]
   public List<Type3ListItem> Type3 {get; set;}
}

public class Type3ListItem
{
   public string ABC {get; set;}
   public string DEF {get; set;}
}

我想使用System.Xml.Serialization进行反序列化,请告知如何继续使用此用例。还建议使用System.Runtime.Serialization.Formatters.Binary;优于System.Xml.Serialization,以获得更好的性能来使用大小为50MB(大约)的XML。

0 个答案:

没有答案