Link to home
Start Free TrialLog in
Avatar of TimHudspith
TimHudspith

asked on

Iterate a structure to get the names and values of its members

I want to iterate a structure in order to build a string out of the name and value of its members. The following code seems to be what I need but the .GetValue method expects an object parameter that I don't understand:

Dim sb As New System.Text.StringBuilder
Dim t As Type = GetType(myStructure)
For Each f As System.Reflection.FieldInfo In t.GetFields
        sb.AppendLine(f.Name & " = " & f.GetValue(??) & ", ")
Next f

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TimHudspith
TimHudspith

ASKER

Got it. Thanks all.