How to iterate over the properties of an object in vb.net?
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
精彩评论