[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)