我正在尝试使用反射序列化从另一个继承的类的属性,但我只想序列化子类的属性,而不是父类的属性。我怎样才能做到这一点?
这就是我正在做的事情,不幸的是它也得到了父类的所有属性,正如人们所期望的那样:
Public Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement) Implements Interfaces.ICustomXMLSerialization.SaveData
Dim elements As New List(Of System.Xml.Linq.XElement)
Dim ci As CultureInfo = CultureInfo.InvariantCulture
With elements
Dim props As PropertyInfo() = Me.GetType.GetProperties()
For Each prop As PropertyInfo In props
If TypeOf Me.GetType.GetProperty(prop.Name).PropertyType Is IList Then
.Add(New XElement(prop.Name, DWSIM.App.ArrayToString(Me.GetType.GetProperty(prop.Name).GetValue(Me, Nothing), ci)))
ElseIf TypeOf Me.GetType.GetProperty(prop.Name).GetValue(Me, Nothing) Is Double Then
.Add(New XElement(prop.Name, Double.Parse(Me.GetType.GetProperty(prop.Name).GetValue(Me, Nothing)).ToString(ci)))
Else
.Add(New XElement(prop.Name, Me.GetType.GetProperty(prop.Name).GetValue(Me, Nothing)))
End If
Next
End With
Return elements
End Function
在此先感谢,丹尼尔