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_Collections_Vb.net 2010 - Fatal编程技术网

Vb.net 将类的属性作为集合检索

Vb.net 将类的属性作为集合检索,vb.net,oop,reflection,collections,vb.net-2010,Vb.net,Oop,Reflection,Collections,Vb.net 2010,我正在做一个小项目,但为了让它继续运行,遇到了一些麻烦 我有一个全局变量: Public Stations As New Microsoft.VisualBasic.Collection() 和2类:站和单元: Public Class Station Property name As String Property stype As String Property units As New Collection End Class Public Class uni

我正在做一个小项目,但为了让它继续运行,遇到了一些麻烦

我有一个全局变量:

Public Stations As New Microsoft.VisualBasic.Collection()
和2类:
单元

Public Class Station

    Property name As String
    Property stype As String
    Property units As New Collection
End Class

Public Class unit
     Property name As String
     Property lbl As String
     Property ip As String
     Property utype As String
End Class
我想你可以在这里看到层次结构:

Collection Stations -> Object Station -> Collection Units -> Object Unit
有一个代码可以从XML文件中获取数据,并根据它将对象添加到上面的集合中

但是,我不知道如何根据
站点
集合检索单位集合。 我试过这样的方法:

    Dim st = Stations.Item("The key of a specific object in the Stations collection")
    Dim stUnits = st.GetType().GetProperty("units")
但是当我试图检索
stUnits
集合时:

For Each unit In stUnits
它说
stUnits
不是一个集合。 我有点困惑,谢谢你的帮助。

我真傻。 忘记将
st
设置为桩号对象

Dim st As Station = Stations.Item("The key of a specific object in the Stations collection")
然后,简单地说:

Dim stUnits = st.units