I am trying to serialize the properties of a class that inherits from another using Reflection, but I would like to serialize only the properties of the child class, not the parent ones. How can i do this?
This is what I do, and unfortunately, it gets all the properties of the parent class, as you would expect:
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
Thanks in advance, Daniel
source share