5 Replies - 894 Views - Last Post: 11 September 2019 - 04:28 AM Rate Topic: -----

#1 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

How to loop through a VB.net property list<of t> in a class

Posted 10 September 2019 - 01:32 PM

I have a class that has a property that is a List<of T>.
I can loop through the class and get the properties, but when I get to the property that is a list I cannot get to the property list.
Any help would be appreciated.

Here is the looping code
 Dim t As Type = PartParam.GetType()
            Dim properties() As PropertyInfo = t.GetProperties()

            'Dim t As Type = PartParam.GetType()
            Dim x As Integer = 0
            For Each Prop As PropertyInfo In properties
                If Prop.CanRead Then
                    If Prop.GetIndexParameters().Length = 0 And Prop.PropertyType.IsGenericType = False Then
                        Debug.Print("Name = " & Prop.Name & ", " & Prop.GetValue(PartParam, Nothing))
                        'Console.WriteLine("{0}: {1}", Prop.Name, Prop.GetValue(PartParam, Nothing))
                        'Console.ReadLine()
                    Else 'detect indexed object
                        Dim p As ParameterInfo() = Prop.GetIndexParameters()

                        For Each Index In Prop.GetIndexParameters()
                            Debug.Print("Count = " & Prop.GetIndexParameters().Count)
                            Debug.Print("Index Type = " & Index.GetType.ToString & ", Uppber Bound = " & Prop.GetIndexParameters().GetLowerBound(0))
                            Debug.Print("Name = " & Prop.Name & Index.Name & ", " & Prop.GetValue(PartParam, {Index}))
                            x = x + 1
                        Next
                    End If
                End If
            Next



Here is the class being used
Imports HMS_Timing_Generator


<Serializable()> Public Class cParamGroup

    'Inherits cMotor
    'Implements IGearBox
    'Implements IDriveTrain
    'Implements IAxisTypeParam
    'Implements IMotor

    Private mCustomer As String
    Private mSONum As String
    Private mStyle As String
    Private mPressStroke As Single
    Private mPressType As String
    Private mLinkPressID As Single
    Private mRamUp As String
    Private mRamDist As List(Of Single)
    Private mPressLine As String
    Private mFileNumber As String
    Private mPartDesc As String
    Private mSpm As Single
    Private mCurrentFile As String
    Private mCount As Integer
    Public AxisType(MaxAisType) As cAxisType
    Public DriveTrain(MaxAisType) As cDriveTrain
    Public GearBox(MaxAisType) As cGearBox
    Public AxisTypeParam(MaxAisType) As cAxisTypeParam
    ' Public Motor(MaxAisType) As cMotor

    'Public Motor(MaxAisType) As cMotor
    ' Public Motor(MaxAisType) As stMotor
    ''' <summary>
    ''' Initializes a new instance of the <see cref="cParamGroup"/> class.
    ''' Public Constructor
    ''' </summary>
    Public Sub New()

        For Loop1 As Integer = 0 To MaxAisType
            AxisType(Loop1) = New cAxisType
            DriveTrain(Loop1) = New cDriveTrain
            GearBox(Loop1) = New cGearBox
            AxisTypeParam(Loop1) = New cAxisTypeParam
            ' Motor(Loop1) = New cMotor
            'Motor(Loop1) = New stMotor
        Next Loop1
        mRamDist = New List(Of Single)

    End Sub
    Public Property CurrentFile As String
        Set(ByVal val As String)
            mCurrentFile = val
        End Set
        Get
            Return mCurrentFile
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the press line.
    ''' </summary>
    ''' <value>
    ''' The press line property.
    ''' </value>
    Public Property PressLine As String
        Set(ByVal val As String)
            mPressLine = val
        End Set
        Get
            Return mPressLine
        End Get
    End Property
    ''' <summary>
    ''' Gets or sets the file number.
    ''' </summary>
    ''' <value>
    ''' The file number property.
    ''' </value>
    Public Property FileNumber As String
        Set(ByVal val As String)
            mFileNumber = val
        End Set
        Get
            Return mFileNumber
        End Get
    End Property
    ''' <summary>
    ''' Gets or sets the part desc.
    ''' </summary>
    ''' <value>
    ''' The part desc.
    ''' </value>
    Public Property PartDesc As String
        Set(ByVal val As String)
            mPartDesc = val
        End Set
        Get
            Return mPartDesc
        End Get
    End Property
    ''' <summary>
    ''' Gets or sets the SPM.
    ''' </summary>
    ''' <value>
    ''' The SPM.
    ''' </value>
    Public Property Spm As Single
        Set(ByVal val As Single)
            mSpm = val
        End Set
        Get
            Return mSpm
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the customer.
    ''' </summary>
    ''' <value>
    ''' The customer.
    ''' </value>
    Public Property Customer As String
        Set(ByVal val As String)
            mCustomer = val
        End Set
        Get
            Return mCustomer
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the so number.
    ''' </summary>
    ''' <value>
    ''' The so number property.
    ''' </value>
    Public Property SoNumber As String
        Set(ByVal val As String)
            mSONum = val
        End Set
        Get
            Return mSONum
        End Get
    End Property
    ''' <summary>
    ''' Gets or sets the style.
    ''' </summary>
    ''' <value>
    ''' The style property.
    ''' </value>
    Public Property Style As String
        Set(ByVal val As String)
            mStyle = val
        End Set
        Get
            Return mStyle
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the press stroke.
    ''' </summary>
    ''' <value>
    ''' The press stroke property.
    ''' </value>
    Public Property PressStroke As Single
        Set(ByVal val As Single)
            mPressStroke = val
        End Set
        Get
            Return mPressStroke
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the type of the press.
    ''' </summary>
    ''' <value>
    ''' The type of the press property.
    ''' </value>
    Public Property PressType As String
        Set(ByVal val As String)
            mPressType = val
        End Set
        Get
            Return mPressType
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the link press identifier.
    ''' </summary>
    ''' <value>
    ''' The link press identifier property.
    ''' </value>
    Public Property LINKPressID As Single
        Set(ByVal val As Single)
            mLinkPressID = val
        End Set
        Get
            Return mLinkPressID
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the ram up.
    ''' </summary>
    ''' <value>
    ''' The ram up property.
    ''' </value>
    Public Property RamUp As String
        Set(ByVal val As String)
            mRamUp = val
        End Set
        Get
            Return mRamUp
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the ram dist.
    ''' </summary>
    ''' <value>
    ''' The ram dist property.
    ''' </value>
    Public Property RamDist() As List(Of Single)
        Set(ByVal value As List(Of Single))
            mRamDist = value
        End Set
        Get
            Return mRamDist
        End Get
    End Property


    Public Function GetCount() As Integer
        GetCount = mRamDist.Count

    End Function

End Class





Sorry the property in the class in question is RamDist() at the end of the class

Is This A Good Question/Topic? 0
  • +

Replies To: How to loop through a VB.net property list<of t> in a class

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,228
  • Joined: 12-December 12

Re: How to loop through a VB.net property list<of t> in a class

Posted 10 September 2019 - 11:45 PM

Does the code generate an error? What are the error details and on what line.

Place a breakpoint on the line and explore the variables and properties that are available at that point.
Was This Post Helpful? 0
  • +
  • -

#3 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: How to loop through a VB.net property list<of t> in a class

Posted 11 September 2019 - 03:57 AM

View Postandrewsw, on 10 September 2019 - 11:45 PM, said:

Does the code generate an error? What are the error details and on what line.

Place a breakpoint on the line and explore the variables and properties that are available at that point.


Hello,

There is no errors when it gets tot he section of code to loop through the property list does not pull out each of the items. I have attached the section of code. I am sure that I am missing something here, but not sure what yet.
Thank You for the feedback
For Each Index In Prop.GetIndexParameters()
                            Debug.Print("Count = " & Prop.GetIndexParameters().Count)
                            Debug.Print("Index Type = " & Index.GetType.ToString & ", Uppber Bound = " & Prop.GetIndexParameters().GetLowerBound(0))
                            Debug.Print("Name = " & Prop.Name & Index.Name & ", " & Prop.GetValue(PartParam, {Index}))
                            x = x + 1
                        Next



Was This Post Helpful? 0
  • +
  • -

#4 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: How to loop through a VB.net property list<of t> in a class

Posted 11 September 2019 - 04:05 AM

View Posttneon1, on 11 September 2019 - 03:57 AM, said:

View Postandrewsw, on 10 September 2019 - 11:45 PM, said:

Does the code generate an error? What are the error details and on what line.

Place a breakpoint on the line and explore the variables and properties that are available at that point.


Hello,

There is no errors when it gets tot he section of code to loop through the property list does not pull out each of the items. I have attached the section of code. I am sure that I am missing something here, but not sure what yet.
Thank You for the feedback
For Each Index In Prop.GetIndexParameters()
                            Debug.Print("Count = " & Prop.GetIndexParameters().Count)
                            Debug.Print("Index Type = " & Index.GetType.ToString & ", Uppber Bound = " & Prop.GetIndexParameters().GetLowerBound(0))
                            Debug.Print("Name = " & Prop.Name & Index.Name & ", " & Prop.GetValue(PartParam, {Index}))
                            x = x + 1
                        Next




One additional piece of information is that it looks like the index from the for each loop is not being declared for the loop exits out right away. I wounder if this line is incorrect?
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,228
  • Joined: 12-December 12

Re: How to loop through a VB.net property list<of t> in a class

Posted 11 September 2019 - 04:07 AM

Note that you do not need to quote a previous post each time, there is a Reply button further down the page.
Was This Post Helpful? 0
  • +
  • -

#6 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: How to loop through a VB.net property list<of t> in a class

Posted 11 September 2019 - 04:28 AM

Thank You for the tip, I am new to the forum
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1