Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>try this:</p> <pre><code>[TestFixture] public class BilldrTest { [Test] public void SerializeDeserializeTest() { var foo = new Foo(); foo.Bars.Add(new Bar { Id = 1 }); foo.Bars.Add(new Bar { Id = 2 }); var xmlSerializer = new XmlSerializer(typeof (Foo)); var stringBuilder = new StringBuilder(); using (var stringWriter = new StringWriter(stringBuilder)) { xmlSerializer.Serialize(stringWriter, foo); } string s = stringBuilder.ToString(); Foo deserialized; using (var stringReader = new StringReader(s)) { deserialized = (Foo) xmlSerializer.Deserialize(stringReader); } Assert.AreEqual(2,deserialized.Bars.Count); } } [XmlRoot("Foo")] public class Foo { public Foo() { Bars= new List&lt;Bar&gt;(); } [XmlArray("BarResponses")] [XmlArrayItem(typeof(Bar))] public List&lt;Bar&gt; Bars { get; set; } //some other elements go here. } [XmlRoot("Bar")] public class Bar { [XmlAttribute("id")] public Int32 Id { get; set; } //some other elements go here. } </code></pre> <ul> <li>You can find info on the use of XmlRoot <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlroot.aspx" rel="nofollow">here</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlarrayitems.aspx" rel="nofollow">ArrayItemAttribute</a> is used if you expect the array to contain different types</li> </ul> <p>You would get the same result stripping all attributes except for [XmlAttribute("id")], but I guess this is an excerpt from a context where it all is justified.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload