Solved

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

Posted on 2004-10-07
2
218 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:zebrachris
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12252858
FieldInfo.GetValue?

Bob
0
 

Author Comment

by:zebrachris
ID: 12253037
D'oh - so simple!

Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question