C#C
C#3y ago
hugeman

❔ XML deserialise different types into a single list

I'm using the build in XML serialisation library (unless it's with .NET framework?), and I current have it deserialise a collection of elements into a list of that element type. This is my class:
public class Shortcut {
    [XmlElement("Keystroke")] public List<Keystroke> KeyStrokes { get; set; }
}

public class Keystroke {
    [XmlAttribute("Keycode")] public string KeyCode { get; set; }
    [XmlAttribute("Mods")]    public string Mods { get; set; }
}

But I also want to add a Mousestroke too (LMB, RMB, etc), but I want to maintain the order that they are placed in the XML document, meaning I need them to go into 1 list right? Is it possible to do that for 2 different types or is that a limitation in the serialiser?
Was this page helpful?