Results 1 to 1 of 1

Thread: [2005] Using GetType to Bind to Class Properties

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question [2005] Using GetType to Bind to Class Properties

    I have successfully used this routine to load Class Properties from a DataTable. This ONLY works if the data type in the database and the class property are both strings.

    Code:
        ''' <summary>
        ''' Matches individual rows to Object Properties.
        ''' </summary>
        ''' <param name="DataTable"></param>
        ''' <remarks></remarks>
        Public Overloads Sub BindIndexDefinition(ByVal DataTable As dsQueueProperties.QueuePropertiesDataTable)
            Dim ThisClass As Type = Me.GetType
            For Each MyProp As Reflection.PropertyInfo In ThisClass.GetProperties()
                For Each row As dsQueueProperties.QueuePropertiesRow In DataTable.Rows
                    If row.Name.ToLower.Equals(MyProp.Name.ToLower) Then
                        MyProp.SetValue(Me, row.Value, Nothing)
                        Exit For
                    End If
                Next
            Next
        End Sub
    How would I tweak this so that the line below would dynamically convert the row.Value type to the correct property type of MyProp?

    Code:
    MyProp.SetValue(Me, row.Value, Nothing)
    Last edited by jesus4u; Jun 8th, 2007 at 09:18 AM. Reason: delete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width