Link to home
Start Free TrialLog in
Avatar of zebrachris
zebrachris

asked on

Dynamically read value of a property from a structure or class.

Ok, I pass in an unknown structure into a function.  I can get the name of the structue, and the name of each property within.  How do I get the values?  

    Public Sub GetStructure(ByRef oStructure As Object)
        Dim tStructure As Type = oStructure.GetType
        Dim sTempFieldName As Reflection.FieldInfo
        Dim oValue As Object

        Try
            Console.Write("Structure Name: " & tStructure.Name)

            'for each item in structure, get it's name and value
            For Each sTempFieldName In tStructure.GetFields
                oValue = ?  'Value of oStructure for current field sTempFieldName
                Console.Write("  Variable Name: " & sTempFieldName.Name & " - Value: " & oValue)
            Next
        Catch ex As Exception

        End Try
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
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
Avatar of zebrachris
zebrachris

ASKER

D'oh - so simple!

Thanks