Reputation: 21
I have a class and I'm trying to loop through all the objects in the class.
The code below always has a count of 0
, is there something I'm missing?
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
Upvotes: 1
Views: 31
Reputation: 7517
Value1
to Value4
are not declared as properties, but as variables.
Declare them like this:
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
See also: Difference Between Properties and Variables in Visual Basic
Upvotes: 2