Last Updated: September 09, 2019
· maxxxlounge

VB.NET Convert Custom Object in a Dictionary(Of String, String)

How to convert your fantastic custom Object in Dictionary Of String, String
(maybe useful for csv creating)

Public Class MyObject

'some code ...

Public Function toDictionary() As Dictionary(Of String, String)
    Dim d As New Dictionary(Of String, String)
    For Each p As System.Reflection.PropertyInfo In Me.GetType.GetProperties()
            d.Add(p.Name, p.GetValue(Me, Nothing).ToString)
        Catch ex As Exception
            'write error message
            d.Add(p.Name, ex.Message)
        End Try
    Return d
End Function

'other code ...

End Class