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()
Try
d.Add(p.Name, p.GetValue(Me, Nothing).ToString)
Catch ex As Exception
'write error message
d.Add(p.Name, ex.Message)
End Try
Next
Return d
End Function
'other code ...
End Class
Written by Massimo Fornasier
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vb.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#