簡體   English   中英

如何遍歷vb.net中對象的屬性?

[英]How to iterate over the properties of an object in 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

???

怎么樣?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM