3

如果列表不为空,我可以序列化列表。

但是如果这个列表为空,我会得到一个关于反序列化的空列表。

当列表在序列化时为空时,我必须做什么才能在反序列化时获得空值?

到目前为止,这是我的尝试:

        [System.Xml.Serialization.XmlArray("WorksButIsNoList", IsNullable = true)]
    public MyClass[] WorksButIsNoList { get; set; }

    [System.Xml.Serialization.XmlArray("ThrowsException", IsNullable = true)]
    public List<MyClass> ThrowsException { get; set; }

    [System.Xml.Serialization.XmlElement("IsntNull", IsNullable = true)]
    public List<MyClass> IsntNull { get; set; }

    [System.Xml.Serialization.XmlElement("ThrowsException2", IsNullable = true)]
    public List<int> ThrowsException2 { get; set; }

    [System.Xml.Serialization.XmlElement("IsntNull2", IsNullable = true)]
    public List<int?> IsntNull2 { get; set; }
4

0 回答 0