0

私は小さなプロジェクトに取り組んでいて、それをOOPに維持しようとしていくつかの問題に直面しました。

私はグローバル変数を持っています:

Public Stations As New Microsoft.VisualBasic.Collection()

そして2つのクラス:StationUnit

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ファイルからデータを取得し、それに応じて上記のコレクションにオブジェクトを追加するコードがあります。

しかし、コレクションに基づいてユニットのコレクションを取得する方法がわかりませんでしたStations。私はこのようなことを試みました:

    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コレクションではないと言っています。私は少し混乱しています、可能な限りの助けに感謝します。

4

1 に答える 1

0

愚かな私。stステーション オブジェクトとして設定するのを忘れていました。

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

そして、単純に:

Dim stUnits = st.units
于 2012-05-26T11:27:48.663 に答える