2012-05-26 78 views
0

我正在研究一個小項目,並且遇到了一些麻煩,試圖保持它的OOP。作爲一個集合檢索一個類的屬性

我有一個全局變量:

Public Stations As New Microsoft.VisualBasic.Collection() 

和2類新:Station & Unit

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文件和acco中獲取數據的代碼rding它將對象添加到上面的集合中。

但是,我沒有計算出如何根據Stations集合檢索單元集合。 我想是這樣的:

Dim st = Stations.Item("The key of a specific object in the Stations collection") 
    Dim stUnits = st.GetType().GetProperty("units") 

但是,當我試圖找回集合:

For Each unit In stUnits 

它說不是一個集合。 我有點困惑,謝謝任何可能的幫助。

回答

0

傻我。 忘記將st設置爲電臺對象。

Dim st As Station = Stations.Item("The key of a specific object in the Stations collection") 

然後,簡單地說:

Dim stUnits = st.units 
相關問題