我正在使用XML反序列化来处理来自我正在调用的api的XML响应。我要回来的其中一个属性需要根据班级中的另一个属性进行更改。一个例子:
<XmlRoot("Foot")> _
Public Class Foo
Private m_bar1 As String
Private m_bar2 As String
Private m_rawbar2 As String
<XmlAttribute("Bar1")> _
Public Property Bar1() As String
Get
return m_bar1
End Get
Set(value As String)
m_bar1 = value
End Set
End Property
<XmlAttribute("Bar2")> _
Public Property RawBar2() As String
Get
return m_rawbar2
End Get
Set(value As String)
m_rawbar2= value
'This won't (always) work because the order in which the
'properties are deserialized is unknown
'm_bar2 = m_bar1 & m_rawbar2
End Set
End Property
<XmlIgnore()> _
Public ReadOnly Property Bar2() As String
Get
return m_bar2
End Get
End Property
End Class
在我的情况下,bar1将是一个url,bar2将是同一域上的相对路径。我可以设置m_bar2的唯一时间是每个属性被反序列化,因为订单是未知的。最好的方法是什么?