xml序列化具有相同类型元素但名称不同的数组C#

时间:2019-01-29 20:53:29

标签: c# xml-serialization xml-deserialization

我在这样的类中使用xml序列化/反序列化:

[XmlChoiceIdentifier("styleEnumArray")]
[XmlElement("style", Type=typeof(ARStyle))]
[XmlElement("point", Type = typeof(ARStyle))]
[XmlElement("line", Type = typeof(ARStyle))]
[XmlElement("surface", Type = typeof(ARStyle))]
[XmlElement("polygon", Type = typeof(ARStyle))]
[XmlElement("area", Type = typeof(ARStyle))]
public ARStyle[] styles
{
    get; set;
}


    [XmlIgnore]
    public StyleEnum[] styleEnumArray = new StyleEnum[]{
        StyleEnum.style,
        StyleEnum.line,
        StyleEnum.point,
        StyleEnum.polygon,
        StyleEnum.surface
    }


/// <summary>
/// Possible XML element names for ARStyle
/// </summary>
public enum StyleEnum
{
    style,
    point,
    line,
    surface,
    polygon,
    area
}

我的目标是通过元素名称的任意组合,能够拥有所需的样式。当前,只要有两个具有相同名称的元素,此操作就会中断。有人可以帮忙吗?

0 个答案:

没有答案