'IU2defineData类名
'IU2defineData类中IU2AddressInf类名
'address是IU2AddressInf类中的字段
Private Shared mIU2Data As IU2defineData
Public Function GetDate() As Datatable
Dim t As Type = GetType(IU2defineData)
Dim address As FIEldInfo = GetType(IU2AddressInf).GetFIEld("address`")
Dim value As FIEldInfo = GetType(IU2AddressInf).GetFIEld("value")
Dim comment As FIEldInfo = GetType(IU2AddressInf).GetFIEld("Comment")
Dim dt As Datatable = New Datatable
Dim rows As DaTarow
Dim fIEldKey As String = nothing
Dim fIElds() As FIEldInfo
Try
dt.Columns.Add("address",GetType(String))
dt.Columns.Add("value",GetType(String))
dt.Columns.Add("`data",GetType(String))
dt.Columns.Add("Comment",GetType(String))
fIElds = t.GetFIElds()
For Each fIEld As FIEldInfo In fIElds
'取到类中变量值 fIEldKey = fIEld.name Dim addressValue As String = address.GetValue(fIEld.GetValue(mIU2Data)) Dim strvalue As String = value.GetValue(fIEld.GetValue(mIU2Data)) Dim strComment As String = comment.GetValue(fIEld.GetValue(mIU2Data)) rows = dt.NewRow rows.Item("address") = fIEldKey rows.Item("value") = addressValue rows.Item("data") = strvalue rows.Item("Comment") = strComment dt.Rows.Add(rows)` Next Catch ex As Exception End Try Return dt End Function
总结以上是内存溢出为你收集整理的Vb.Net 通过反射获取类的字段值全部内容,希望文章能够帮你解决Vb.Net 通过反射获取类的字段值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)