0

I am trying to iterate through properties of properties. Below is my sample class

Public Class Doc
    Public Property DocName As String
    Public Property flds As Flds
    Public Sub New()
        flds = New Flds()
    End Sub

End Class

Public Class Flds
    Public Property id As ID
    Public Property name As Name
    Public Sub New()
        id = New ID()
        name = New Name()
    End Sub
End Class
Public Class ID
    Public Property type As Integer
    Public Property value As String
    Public Property page As Integer
End Class
Public Class Name
    Public Property type As String
    Public Property value As String
    Public Property page As Integer
End Class

And below is the code in my main module, here I am iterating through properties in Flds object, and within this, I need to iterate through properties of each property. Great if anyone could advise please.

 Dim doc As Doc = New Doc()

 Dim t As Type = doc.flds.GetType
 For Each p As System.Reflection.PropertyInfo In t.GetProperties()
     If p.CanRead Then
         Dim strName = p.Name.ToString()
         Dim strValue As String = p.GetValue(doc.flds, Nothing).ToString()
     End If
 Next
Chembu
  • 9
  • 2
  • What's your problem? What isn't working? – Craig Aug 18 '22 at 14:05
  • In the code I pasted above, I am able to iterate through the properties of Flds class but each of these fields proerties is a class, how can I iterate through the properties of these properties. – Chembu Aug 19 '22 at 01:30
  • You should be able to get the type of each field, and then it's the same as iterating over the members of the containing type. – Craig Aug 19 '22 at 13:38
  • Thank you very much Craig, this is working fine. – Chembu Aug 22 '22 at 22:19

0 Answers0