2011-03-23 6 views
2

내 프로젝트에서 복잡한 계산 객체를 디버깅 중이며 테스트를 쉽게하기 위해 텍스트 상자에 다양한 속성을 표시하고 싶습니다.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 

같은 일을 할 수 ???

어떻게?

답변

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 
+0

네, 반성은 여기에 친구입니다. –

+0

감사합니다. 훌륭합니다. – Alex

관련 문제