我正在使用 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 的时间是当每个属性都被反序列化时,因为顺序是未知的。最好的方法是什么?