Note that there are some explanatory texts on larger screens.

plurals
  1. POXML serialization of a collection in C#
    text
    copied!<p>I have two classes as follows:</p> <pre><code> public class Info { [XmlAttribute] public string language; public int version; public Book book; public Info() { } public Info(string l, int v, string author, int quantity, int price) { this.language = l; this.version = v; book = new Book(author, quantity, price); } } public class Book { [XmlAttribute] public string author; public int quantity; public int price; [XmlIgnore]public int total; public NameValueCollection nvcollection = new NameValueCollection(); public Book() { } public Book(string author, int quantity, int price) { this.author = author; this.quantity = quantity; this.price = price; total = quantity * price; nvcollection.Add(author, price.ToString()); } } </code></pre> <p>I have created an ArrayList which adds the two instances of Info class as follows:</p> <pre><code> FileStream fs = new FileStream("SerializedInfo.XML", FileMode.Create); List&lt;Info&gt; arrList = new List&lt;Info&gt;(); XmlSerializer xs = new XmlSerializer(typeof(List&lt;Info&gt;)); Info pObj = new Info("ABC", 3, "DEF", 2, 6); Info pObj1 = new Info("GHI", 4, "JKL", 2, 8); arrList.Add(pObj); arrList.Add(pObj1); xs.Serialize(fs, arrList); fs.Close(); </code></pre> <p>But when I try to serialize, I get an exception as "There was an error reflecting type 'System.Collections.Generic.List`1[ConsoleApplicationSerialization.Info]'."</p> <p>Can anyone help me with it?</p> <p>Also, instead of namevaluecollection, which type of structure can i use?</p>
 

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