Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IXmlSerializable doesn't get deserialized when used in class
- [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 = 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));
- }
- }
- 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));
- }
- 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);
Advertisement
Add Comment
Please, Sign In to add comment