Salve, avrei bisogno di leggere una istanza ad una struttura con un for each, in modo da leggere tutti i nomi di variabili e il loro valore.
Ho visto che si può fare su una struttura, es.:
Public Structure kkk
Public a As String
Public b As Integer
End Structure
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Infos() As FieldInfo
Infos = GetType(kkk).GetFields
Dim nome As String
Dim tipo As Object
For Each fi As FieldInfo In Infos
nome = fi.Name
tipo = fi.FieldType
Next
End Sub
in questo caso ogni ciclo leggerà il nome di della variabile e il tipo.
---------------------------------------------------------
ma come faccio a leggere il nome del campo e il suo valore quando creo una istanza? es.:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim istanza As New kkk
istanza.a = "stringa"
istanza.b = 6
Dim Infos() As FieldInfo
Infos = GetType(istanza).GetFields
Dim nome As String
Dim tipo As Object
For Each fi As FieldInfo In Infos
nome = fi.Name
tipo = fi.FieldType
Next
End Sub
'questo non funziona
oppure accedere alla variabile di una istanza con un indice, o con una variabile e recuperarne il valore. es.:
dim valore as string
valore = istanza.(1).GetValue
oppure
valore = istanza.("a").GetValue
(naturalmente GetValue non è corretto, è che non so cosa usare...