Listing Structure Properties

jswota

Well-known member
Joined
Feb 23, 2009
Messages
49
Programming Experience
Beginner
Hi.

I am having some trouble using Refelction to list the properties of a user defined structure. I need to get a list of the properties and their values.

Here is the structure:
Public Structure typ_Hole
Friend Type As enum_Hole_Type
Friend Index As Integer
Friend Face As String
Friend x As typ_Coordinate_Data
Friend y As typ_Coordinate_Data
Friend Diameter As Double
Friend Misc_1 As Double
Friend Misc_2 As Double
Friend Length As Double
Friend Angle As Double
Friend Remarks As String
End Structure

Here is the code:

For Each Hole As typ_Hole In m_Holes 'm_Holes is an array of typ_Hole
Dim _info As System.Reflection.PropertyInfo() = _
Hole.GetType.GetProperties

For index As Integer = 0 To _info.Length - 1
' I have defined the structure typ_Hole as shown
' The problem is that this code doesn't list
' the properties and value. The _info collection
' is always empty.
Next
Next

Could anyone please shed some light on this matter?

Thanks,
Joel
 
Your structure doesn't have any properties, it only has fields. Also note that to list non-public members you have to set the binding flags parameter (Instance Or NonPublic).
 
Hi John.

Thanks for the reply. That really helped.

One problem that i am still having is that i can get the field name from the .Name property but i cannot get the field value from the field for the current array member. Do you know if this is possible?

Thanks again for the help,
Joel
 
theFieldInfo.GetValue(instance) where instance is the structure object.
 
Back
Top