在 .Net 的環境下,所有的 Class (類)  都延伸自  Syatem.Object

而在 Object 下有些基本 Function

其中  GetType 是一個非常豐富的 資料集合,透過 GetType 可以 取出物件中非常多 的資料
由其是當自建 Class 時,可以由其中取得  Fields 的資料


Class cABC
    public aaa as string = ""                        'string的初始宣告是 string.Empty  必須先填個空字串   不然取getFields 時會告知未宣告
    public bbb as integer
    public ddd as double
end class


getType 中的 GetValue 和  setValue 是今天的主角

Dim test as new cABC

'以下逐一將 宣告成 cABC 的 test 中的 Field 一個一個取出

For Each field in test.getType.Fields
      dim A = field.getValue()
      msgbox(A.tostring)
end For

'在來是把值填進去    填進去就比較麻煩 因為三個的資料型態都不一樣
'實際在運用時  有多做一個  資料型態判別Function
'setValue 需要原先物件的配合    field.setValue(test,      要填入的値           )


For Each field in test.getType.GetFields

      select case field.FieldsName

            case "String"
                    field.setValue(test , "100")
            case "Integer"
                    field.setValue(test, 100)
            case "Double"
                    field.setValue(test,100.0)
      end select

end for



以上  用在 SE 的資料傳輸  物件化的基本................................

文章標籤
全站熱搜
創作者介紹
創作者 Rh 的頭像
Rh

程式狂想曲

Rh 發表在 痞客邦 留言(0) 人氣(263)