Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem Serializing a Class Containing a Collection using XML Serialization
    text
    copied!<p>I have this xml snippet as part of a xml file that will be deserialized to a c# object</p> <pre><code>&lt;EmailConfiguration&gt; &lt;SendTo&gt; &lt;Address&gt;myEmailAdress@bah.com&lt;/Address&gt; &lt;Address&gt;also send to&lt;/Address&gt; &lt;/SendTo&gt; &lt;CC&gt; &lt;Address&gt;CC&lt;/Address&gt; &lt;/CC&gt; &lt;BCC&gt; &lt;Address&gt;BCC&lt;/Address&gt; &lt;/BCC&gt; &lt;/EmailConfiguration&gt; </code></pre> <p>Notice the SendToAddress is a collection of Addresses</p> <pre><code>&lt;Address&gt;myEmailAddress@bah.com&lt;/Address&gt; &lt;Address&gt;also send to&lt;/Address&gt; </code></pre> <p>My Class currently looks like this </p> <pre><code>public class SendTo { public string Address { get; set; } } </code></pre> <p>This is good for 1 address, how do I change the class so that it can handle more than 1 address.</p> <p>I tried </p> <pre><code>public class SendTo { public string[] Address { get; set; } } </code></pre> <p>But with this, nothing gets populated when the xml is deserialized to a class.</p> <p><strong>Update</strong></p> <p>tried...also without success....</p> <pre><code>public class SendTo { public List&lt;string&gt; Address { get; set; } } </code></pre> <p>Here is the entire class</p> <pre><code>namespace myConfiguration { public class myConfiguration { private string myID; public string MyID { get { return myID; } set { myID = value; } } public Locale Locale { get; set; } public EmailConfiguration EmailConfiguration { get; set; } } public class Locale { public string LocaleName { get; set; } public string LocaleCode { get; set; } } public class EmailConfiguration { public SendTo SendTo { set; get; } public SendTo CC { set; get; } public SendTo BCC { set; get; } } public class SendTo { public List&lt;string&gt; Address { get; set; } } </code></pre> <p>}</p> <p>Here is the XML that I am deserializing from ...</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;MyConfiguration&gt; &lt;MyID&gt;vpfaewb&lt;/MyID&gt; &lt;Locale&gt; &lt;LocaleName&gt;cs-CZ&lt;/LocaleName&gt; &lt;LocaleCode&gt;1029&lt;/LocaleCode&gt; &lt;/Locale&gt; &lt;EmailConfiguration&gt; &lt;SendTo&gt; &lt;Address&gt;my email address&lt;/Address&gt; &lt;Address&gt;also send to&lt;/Address&gt; &lt;/SendTo&gt; &lt;CC&gt; &lt;Address&gt;CC&lt;/Address&gt; &lt;/CC&gt; &lt;BCC&gt; &lt;Address&gt;BCC&lt;/Address&gt; &lt;/BCC&gt; &lt;/EmailConfiguration&gt; &lt;/MyConfiguration&gt; </code></pre>
 

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