Using reflection in Windows form to get values

shruts

Member
Joined
Sep 13, 2011
Messages
7
Programming Experience
1-3
Dear ALL,

I have the following class:

I am able to get all the public fields inside class speed using the following code:

For Each rField As FieldInfo In _axes.ctrl(j).spd.GetType().GetFields(BindingFlags.Public Or BindingFlags.Instance)
Dim iType As Double
Dim t As Type = _axes.ctrl(j).spd.GetType
Dim mySpdtype As Type() = t.GetNestedTypes(BindingFlags.Public Or BindingFlags.Instance) 'Get nested class in Speed class
iType = _axes.ctrl(j).spd.GetType().GetField(rField.Name).GetValue(_axes.ctrl(j).spd)
AddTextBox(i, rField.Name, iType)
i += 1
Next

Since my variable iType is of double it is unable to cast the nested type inside Class Speed. I need a way to only display public fields inside Speed class and ignore instance variables. Later on I want to be also able to get public fields from my nested class. Please see the class hierarchy below:

Public Class Speed
Public Proportional As Double = 5
Public Integral As Double = 0.004
Public FilterTimeConst As Double = 0.0008
Public isq1 As New isq_filter1
Public isq2 As New isq_filter2
Public isq3 As New isq_filter3

Public Enum ISQFiltType
ncOFF = 0
ncLOW_PASS
ncNOTCH
ncZ_TRANS
ncISQF_LIM
ncISQF_LIM2
ncISQF_LIM3
ncISQF_COMP
ncBIQUAD
End Enum

Public Class isq_filter1

Public A0 As Double = 1360
Public A1 As Double = 400
Public B0 As Double = 0
Public B1 As Double = 0
Public B2 As Double = 0

End Class

Public Class isq_filter2

Public type As String
Public A0 As Double = 1650
Public A1 As Double = 800
Public B0 As Double = 0
Public B1 As Double = 0
Public B2 As Double = 0

End Class

Public Class isq_filter3

Public A0 As Double = 0
Public A1 As Double = 0
Public B0 As Double = 0
Public B1 As Double = 0
Public B2 As Double = 0

End Class

End Class
 

Latest posts

Back
Top