Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VB.NET上反映派生类的唯一子属性_Vb.net_Oop_Reflection - Fatal编程技术网

在VB.NET上反映派生类的唯一子属性

在VB.NET上反映派生类的唯一子属性,vb.net,oop,reflection,Vb.net,Oop,Reflection,我试图使用反射序列化从另一个继承的类的属性,但我只想序列化子类的属性,而不是父类的属性。我该怎么做 这就是我正在做的,不幸的是,它也得到了父类的所有属性,正如人们所期望的: Public Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement) Implements Interfaces.ICustomXMLSerialization.SaveData Dim

我试图使用反射序列化从另一个继承的类的属性,但我只想序列化子类的属性,而不是父类的属性。我该怎么做

这就是我正在做的,不幸的是,它也得到了父类的所有属性,正如人们所期望的:

    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
提前感谢,,
Daniel

您需要指定
BindingFlags.DeclaredOnly
作为
GetProperties
调用的参数


不过,这些标志的使用经常会遇到一些问题,因此可能需要进行一些实验才能找到所需的标志的精确组合。枚举的MSDN描述为。

根据定义,父对象的属性也是子对象的属性!