Guest User

Untitled

a guest
Aug 12th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. IXmlSerializable doesn't get deserialized when used in class
  2. [XmlRoot("company"), DataContract(Name = "company")]
  3. public class Company : IProvideSerialization
  4. {
  5. /// <summary>
  6. /// Stock exchange the company is in.
  7. /// </summary>
  8. /// <see cref="https://developer.linkedin.com/documents/company-lookup-api-and-fields"/>
  9. /// <remarks>Available only for public companies.</remarks>
  10. [XmlElement("stock-exchange"), DataMember(Name = "stock-exchange", EmitDefaultValue = false, IsRequired = false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
  11. protected SerializableEnum<StockExchange> StockExchangeForXML;
  12. public static Company FromXml(String XML)
  13. {
  14. XmlSerializer x = new XmlSerializer(typeof(Company));
  15. return (Company)x.Deserialize(new StringReader(XML));
  16. }
  17. }
  18.  
  19. public static SerializableEnum<T> FromXml(string XML)
  20. {
  21. XmlRootAttribute XR = (XmlRootAttribute)System.Attribute.GetCustomAttribute(typeof(T), typeof(XmlRootAttribute));
  22. XmlSerializer x = new XmlSerializer(typeof(SerializableEnum<T>), new XmlRootAttribute() { ElementName = XR.ElementName, IsNullable = true });
  23. return (SerializableEnum<T>)x.Deserialize(new StringReader(XML));
  24. }
  25.  
  26. String StockXML = "<stock-exchange><code>NMS</code><name>NASDAQ</name></stock-exchange>";
  27. String CompanyXML = "<company><stock-exchange><code>NMS</code><name>NASDAQ</name></stock-exchange></company>";
  28.  
  29. SerializableEnum<StockExchange> Stock = SerializableEnum<StockExchange>.FromXml(StockXML);
  30. Company Cmp = Company.FromXml(CompanyXML);
Advertisement
Add Comment
Please, Sign In to add comment