Otherwise, if you need to use it: enjoy.
Public Class DictionaryMapper(Of T As {Class, New})
Public Shared Function MapDictionaryToObject(ByVal entity As T, ByVal dictionary As IDictionary) As T
Dim properties = entity.GetType().GetProperties()
For Each pInfo As System.Reflection.PropertyInfo In properties
If dictionary.Contains(pInfo.Name) Then
Dim infoType = pInfo.PropertyType
Dim nullableType = Nullable.GetUnderlyingType(pInfo.PropertyType)
If Not nullableType Is Nothing Then
infoType = nullableType
End If
Dim conversion = Convert.ChangeType(dictionary(pInfo.Name), infoType)
pInfo.SetValue(entity, conversion, Nothing)
End If
Next
Return entity
End Function
End Class

New Topic/Question
Reply



MultiQuote








|