我有一个类,我正在尝试遍历类中的所有对象。
下面的代码总是有0
,我有什么遗漏吗?
Public Class SomeClass
Public Value1 As String
Public Value2 As String
Public Value3 As String
Public Value4 As String
End Class
Public Function FindClassValue() As Boolean
Dim someobj As New SomeClass
Dim myType As Type = someobj.GetType
Dim properties As System.Reflection.PropertyInfo() = myType.GetProperties()
For Each p As System.Reflection.PropertyInfo In properties
Debug.WriteLine(p.Name)
Next
Return Nothing
End Function
答案 0 :(得分:2)
Value1
到Value4
未声明为属性,而是声明为变量。
声明他们是这样的:
Public Class SomeClass
Public Property Value1 As String
Public Property Value2 As String
Public Property Value3 As String
Public Property Value4 As String
End Class
另请参阅: Difference Between Properties and Variables in Visual Basic