开发者

How to iterate over the properties of an object in vb.net?

开发者 https://www.devze.com 2023-02-19 00:11 出处:网络
I\'m debuging an complex calculation object in my project, and I\'d like to show its various and many properties in a textbox, to make my tes开发者_如何学JAVAts easier.

I'm debuging an complex calculation object in my project, and I'd like to show its various and many properties in a textbox, to make my tes开发者_如何学JAVAts easier.

Can I do something like

for each p as someKindOfProperty in MyObject1
  debug.print(p.name & " - " & debug.print p.value)
  textbox1.text = textbox1.text & vbcrlf & p.name & " - " & p.value
next

???

How?


Dim props As PropertyInfo() = GetType(Color).GetProperties(BindingFlags.[Static] Or BindingFlags.[Public])

For Each prop As PropertyInfo In props
    Dim o As Object = prop.GetValue(Nothing, Nothing)
    If o IsNot Nothing Then
        textbox1.Text = Textbox1.text + Constants.vbcrlf + prop.Name + " - " + o.ToString()
    End If
Next
0

精彩评论

暂无评论...
验证码 换一张
取 消