IXmlSerializable doesn't get deserialized when used in class

EdAtun

New Member
\[code\][XmlRoot("company"), DataContract(Name = "company")]public class Company : IProvideSerialization{ /// <summary> /// Stock exchange the company is in. /// </summary> /// <see cref="https://developer.linkedin.com/documents/company-lookup-api-and-fields"/> /// <remarks>Available only for public companies.</remarks> [XmlElement("stock-exchange"), DataMember(Name = "stock-exchange", EmitDefaultValue = http://stackoverflow.com/questions/11455414/false, IsRequired = false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)] protected SerializableEnum<StockExchange> StockExchangeForXML; public static Company FromXml(String XML) { XmlSerializer x = new XmlSerializer(typeof(Company)); return (Company)x.Deserialize(new StringReader(XML)); }}\[/code\]The SerializableEnum implements IXmlSerializable.SerializableEnum also has a FromXml that works; it looks as followed:\[code\] public static SerializableEnum<T> FromXml(string XML) { XmlRootAttribute XR = (XmlRootAttribute)System.Attribute.GetCustomAttribute(typeof(T), typeof(XmlRootAttribute)); XmlSerializer x = new XmlSerializer(typeof(SerializableEnum<T>), new XmlRootAttribute() { ElementName = XR.ElementName, IsNullable = true }); return (SerializableEnum<T>)x.Deserialize(new StringReader(XML)); }\[/code\]When I do:\[code\] String StockXML = "<stock-exchange><code>NMS</code><name>NASDAQ</name></stock-exchange>"; String CompanyXML = "<company><stock-exchange><code>NMS</code><name>NASDAQ</name></stock-exchange></company>"; SerializableEnum<StockExchange> Stock = SerializableEnum<StockExchange>.FromXml(StockXML); Company Cmp = Company.FromXml(CompanyXML);\[/code\]Stock will be populated with the data, but Cmp will not have the Stock data populated (looks like ReadXml never gets called)...I've tried adding additional types to the XmlSerializer (like , new Type[] {typeof(SerializableEnum)}), but that doesn't help.What am I missing here? Thanks.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?
 
Back
Top