Could anyone help me with deserialize and build the model? with this xml:
<event>
<argument type="Type1" id="1" name="test1"/>
<argument type="Type2" id="1" extra="5"/>
</event>
Event class
[XmlType("event")]
public class Event
{
[XmlElement("argument")]
public List<Argument> Arguments { get; set; }
}
Argument class
public abstract class Argument
{
[XmlAttribute("id")]
public int Id { get; set; }
}
Type1 class
public class Type1 : Argument
{
[XmlAttribute("name")]
public string Name { get; set; }
}
Type2 class
public class Type2 : Argument
{
[XmlAttribute("extra")]
public string Extra { get; set; }
}
Inner exception:
{"The specified type is abstract: name='Argument', namespace='', at ."}
Maybe I don't have to use custom deserializer, I just want to deserialize the objects depending on "type" attribute value.
Deserializing way I use:
public static T XmlDeserializeFromString<T>(this string objectData)
{
return (T)XmlDeserializeFromString(objectData, typeof(T));
}
var obj = xml.XmlDeserializeFromString<Event>();