Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Xml Deserialize nested objects
    primarykey
    data
    text
    <p>I'm trying to expand an XML config file containing colors for various things, currently it's looking like this.</p> <pre><code>&lt;Colors&gt; &lt;FooColor1&gt;0x0BD000&lt;/FooColor1&gt; &lt;FooColor2&gt;0x11C711&lt;/FooColor2&gt; &lt;FooColor3&gt;0x224466&lt;/FooColor3&gt; &lt;FooColor4&gt;0xAA3333&lt;/FooColor4&gt; &lt;FooColor5&gt;0x886644&lt;/FooColor5&gt; &lt;/Colors&gt; </code></pre> <p>These all come out as strings and everything works fine and dandy. The problem comes in here, As I said, I'm trying to expand the file, the new format will be like this</p> <pre><code>&lt;Colors&gt; &lt;DetailColors&gt; &lt;FooColor1&gt;0x0BD000&lt;/FooColor1&gt; &lt;FooColor2&gt;0x11C711&lt;/FooColor2&gt; &lt;FooColor3&gt;0x224466&lt;/FooColor3&gt; &lt;FooColor4&gt;0xAA3333&lt;/FooColor4&gt; &lt;FooColor5&gt;0x886644&lt;/FooColor5&gt; &lt;/DetailColors&gt; &lt;GoalColors&gt; //Similar stuff, not actually in yet. &lt;/GoalColors&gt; &lt;/Colors&gt; </code></pre> <p>However, the serialization style that worked with a single level, doesn't seem to be able to handle the nesting. </p> <pre><code>[System.SerializableAttribute()] public class GraphColors { public string FooColor1 { get; set; } public string FooColor2 { get; set; } public string FooColor3 { get; set; } public string FooColor4 { get; set; } public string FooColor5 { get; set; } } [System.SerializableAttribute()] public class DetailColors { [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public GraphColors ColorSchema { get; set; } } [System.SerializableAttribute()] public class Colors { [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] private DetailColors CombinedColors { get; set; } public static GraphColors getColorsFromConfig() { return new XmlSerializer(Colors).Deserialize(path).CombinedColors.ColorSchema } } </code></pre> <p>This worked fine when there wasn't an intermediate object, but now that intermediate object gives a null value. Any help would be greatly appreciated.</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. This table or related slice is empty.
    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