Hi all,
How do we convert a source type into a destination type before using reflection to assign value from source field to destination field in below code snippet:
When I try to assign a boolean value to a custom data type, I get an unhandled excpetion hereCode:Try
tempPropertyInfo = tempDestinationObject.GetType.GetProperty(sourceObjectName)
If Not tempPropertyInfo Is Nothing AndAlso sourceDataTable.Columns.Contains(sourceObjectName) AndAlso tempPropertyInfo.CanWrite Then
Select Case tempPropertyInfo.PropertyType.Namespace
Case "System"
tempPropertyValue = CObj(sourceDataTable.Rows(rowCount).Item(sourceObjectName))
If Not tempPropertyValue Is Nothing AndAlso tempPropertyInfo.PropertyType.FullName = "System.DateTime" Then
tempPropertyValue = CDate(tempPropertyValue)
End If
Case Else
tempPropertyValue = Activator.CreateInstance(tempPropertyInfo.PropertyType)
tempPropertyValue.Value = CObj(sourceDataTable.Rows(rowCount).Item(sourceObjectName))
End Select
If Not tempPropertyValue Is Nothing Then
tempPropertyInfo.SetValue(tempDestinationObject, tempPropertyValue, Nothing)
End If
End If
Catch ex As Exception
End Try
Code:tempPropertyValue.Value = CObj(sourceDataTable.Rows(rowCount).Item(sourceObjectName))
