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
前もって感謝します、ダニエル