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