I'm trying to deserialize a list of RShortcut objects, which is an abstract class. However, XmlSerializer always returns an empty list.
Here's the code I'm running:
String toolbarPath = HttpRuntime.AppDomainAppPath + Settings.Default.DEFAULT_TOOLBAR_PATH;
StreamReader reader = new StreamReader(toolbarPath);
XmlSerializer toolbarSerializer = new XmlSerializer(typeof(List<RShortcut>), new XmlRootAttribute("Shortcuts"));
List<RShortcuts> shortcuts = (List<RShortcut>)toolbarSerializer.Deserialize(reader);
These are the classes' definitions:
[Serializable]
[XmlRoot("Shortcut")]
[XmlType("Shortcut")]
[XmlInclude(typeof(RShortcutPopup))]
[XmlInclude(typeof(RShortcutTab))]
public abstract class RShortcut
{
[XmlAttribute("path")]
public String Path{ get; set; }
}
[Serializable]
[XmlRoot("Popup")]
[XmlType("Popup")]
public class RShortcutPopup : RShortcut
{
}
[Serializable]
[XmlRoot("Tab")]
[XmlType("Tab")]
public class RShortcutTab : RShortcut
{
}
And here's an xml example:
<Shortcuts>
<Tab path="foo.bar.com" />
<Popup path="foo.bar.net"/>
</Shortcuts>
What's the proper way to do it?