我開始寫一個解決方案,並在這裏分享。它可能不完美,但它是一個開始。
Public Shared Function mergeObjectInTemplatedata(template As Object,
source As Object,
Optional parents As List(Of String) = Nothing) As Object
If parents Is Nothing Then
parents = New List(Of String)
End If
For Each prop As PropertyInfo In template.GetType().GetProperties()
Dim value As Type = prop.GetValue(template).GetType()
If value = GetType(String) Or value = GetType(Integer) Then
prop.SetValue(template, getFromSource(source, parents, prop.Name))
Else
parents.Add(prop.Name)
mergeObjectInTemplatedata(prop.GetValue(template), source, parents)
End If
Next
Return template
End Function
Private Shared Function getFromSource(source As Object,
location As List(Of String),
propertyName As String) As Object
Dim obj As Object = source
For Each item As String In location
obj = CallByName(obj, item, CallType.Get)
Next
Return CallByName(obj, propertyName, CallType.Get)
End Function
許多JSON庫支持的屬性用於標記某些性質不該」序列化。檢查您正在使用的序列化程序的文檔。 – mason
@mason嚴重...所以我一直在錯誤的道路上?我使用Newtonsoft JSON。我將檢查文檔 – NLAnaconda
'JsonIgnoreAttribute' – Plutonix