如何在XML序列化上有条件地忽略某些字段

时间:2017-03-21 10:31:15

标签: xml vb.net serialization

我正在尝试编写一个应该将类序列化为XML文件的程序,但最近我的规范发生了变化,现在我有一个以前唯一且非空字段改变如下:

  • 正常情况,与之前一样,字段不会更改[a,b,c]
  • n个字段,带有指向另一个字段ID [a,b,c,id]
  • 的链接

如何更改课程以允许此类行为?

实际值:

    <Serializable>
    Public Class DataType
        Public FieldToChange As New FieldType 'FieldType to change
    End Class

    <Serializable>
    Public class FieldType
        Public a As Integer
        Public b As Integer
        Public c As Integer
    End Class

未来:

    <Serializable>
    Public Class ClassWithElemToChangeType
        <XmlElement("FieldType")> ' Is it right?
        Public FieldToChange As New List(Of FieldType)
    End Class

    <Serializable>
    Public class FieldType
        Public a As Integer
        Public b As Integer
        Public c As Integer
        Public id As Integer
        ' How can i add a field that gets ignored whenever is null
        ' or how can I programmatically tell my serializer to ignore
    End Class

0 个答案:

没有答案