Solved

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

Posted on 2004-10-07
2
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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