Solved

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

Posted on 2004-10-07
2
193 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
Comment Utility
FieldInfo.GetValue?

Bob
0
 

Author Comment

by:zebrachris
Comment Utility
D'oh - so simple!

Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now