Note that there are some explanatory texts on larger screens.

plurals
  1. POIXmlSerializable doesn't get deserialized when used in class
    primarykey
    data
    text
    <pre><code>[XmlRoot("company"), DataContract(Name = "company")] public class Company : IProvideSerialization { /// &lt;summary&gt; /// Stock exchange the company is in. /// &lt;/summary&gt; /// &lt;see cref="https://developer.linkedin.com/documents/company-lookup-api-and-fields"/&gt; /// &lt;remarks&gt;Available only for public companies.&lt;/remarks&gt; [XmlElement("stock-exchange"), DataMember(Name = "stock-exchange", EmitDefaultValue = false, IsRequired = false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)] protected SerializableEnum&lt;StockExchange&gt; StockExchangeForXML; public static Company FromXml(String XML) { XmlSerializer x = new XmlSerializer(typeof(Company)); return (Company)x.Deserialize(new StringReader(XML)); } } </code></pre> <p>The SerializableEnum implements IXmlSerializable.</p> <p>SerializableEnum also has a FromXml that works; it looks as followed:</p> <pre><code> public static SerializableEnum&lt;T&gt; FromXml(string XML) { XmlRootAttribute XR = (XmlRootAttribute)System.Attribute.GetCustomAttribute(typeof(T), typeof(XmlRootAttribute)); XmlSerializer x = new XmlSerializer(typeof(SerializableEnum&lt;T&gt;), new XmlRootAttribute() { ElementName = XR.ElementName, IsNullable = true }); return (SerializableEnum&lt;T&gt;)x.Deserialize(new StringReader(XML)); } </code></pre> <p>When I do:</p> <pre><code> String StockXML = "&lt;stock-exchange&gt;&lt;code&gt;NMS&lt;/code&gt;&lt;name&gt;NASDAQ&lt;/name&gt;&lt;/stock-exchange&gt;"; String CompanyXML = "&lt;company&gt;&lt;stock-exchange&gt;&lt;code&gt;NMS&lt;/code&gt;&lt;name&gt;NASDAQ&lt;/name&gt;&lt;/stock-exchange&gt;&lt;/company&gt;"; SerializableEnum&lt;StockExchange&gt; Stock = SerializableEnum&lt;StockExchange&gt;.FromXml(StockXML); Company Cmp = Company.FromXml(CompanyXML); </code></pre> <p>Stock will be populated with the data, but Cmp will not have the Stock data populated (looks like ReadXml never gets called)...</p> <p>I've tried adding additional types to the XmlSerializer (like , new Type[] {typeof(SerializableEnum)}), but that doesn't help.</p> <p>What am I missing here? Thanks.</p> <p>I think it might be something like that RootElementAttribute that I had to add in the FromXml in the SerializableEnum class. The IXmlSerializable ignored the XmlRoot attribute that the enum had, so I added that code to add it when deserializing. Is there a different way to make this all work togeather?</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