For the display of a list of item, I need to know with generic way to determine if item has a list of this item, it is a simple recursive loop.
I have tried with Reflection as this
Dim detail As New List(Of PersonneSampleModel) From {New PersonneSampleModel With {.Id = 50, .Nom = "Details_Robert", .Prenom = "Details_titi"}}
Dim p = New PersonneSampleModel With {.Id = 1, .Nom = "Robert", .Prenom = "titi", .lst = detail}
Dim p2 = New PersonneSampleModel With {.Id = 2, .Nom = "Jean", .Prenom = "titi2"}
Dim p3 = New PersonneSampleModel With {.Id = 3, .Nom = "Dupont", .Prenom = "titi3"}
Dim p4 = New PersonneSampleModel With {.Id = 4, .Nom = "Sean", .Prenom = "titi3"}
Dim p5 = New PersonneSampleModel With {.Id = 5, .Nom = "Paul", .Prenom = "titi3"}
Dim p6 = New PersonneSampleModel With {.Id = 6, .Nom = "Durant", .Prenom = "titi3"}
Dim lst As New List(Of PersonneSampleModel) From {p, p2, p3, p4, p5, p6}
For Each item In lst
For Each prop in item.GetType().GetProperties
If TypeOf prop Is List(of PersonneSampleModel) ' <= how to determine if prop is List<item>
prop.Dump()
End if
Next
Next
Not Working :
If TypeOf prop Is List(of item.GetType()) 'item.GetType() not defined
If TypeOf prop Is List(of PersonneSampleModel) ' PropertyInfo is not List(of )
My issue is that prop is ever PropertyInfo and not a true type that I can compare.
Thank for your help.
Aucun commentaire:
Enregistrer un commentaire