如何在vb.net中迭代对象的属性?

Ale*_*lex 2 .net vb.net

我正在我的项目中调试一个复杂的计算对象,我想在文本框中显示它的各种属性,以使我的测试更容易.

我能做点什么吗

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
Run Code Online (Sandbox Code Playgroud)

???

怎么样?

Bal*_*a R 5

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
Run Code Online (Sandbox Code Playgroud)