我正在尝试使用Reflection序列化从另一个继承的类的属性,但我想仅序列化子类的属性,而不是父类的属性.我怎样才能做到这一点? 这就是我正在做的事情,不幸的是它正在获得父类的所有
这就是我正在做的事情,不幸的是它正在获得父类的所有属性,正如人们所期望的那样:
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
提前致谢,
丹尼尔
但是,经常会遇到使用这些标志的问题,因此可能需要进行一些实验才能找到所需标记的确切组合.枚举的MSDN描述是here.
