Skip to content

Instantly share code, notes, and snippets.

@kristoferdoman
Last active August 26, 2016 18:40
Show Gist options
  • Save kristoferdoman/8d48497b6fa890c89de7 to your computer and use it in GitHub Desktop.
Save kristoferdoman/8d48497b6fa890c89de7 to your computer and use it in GitHub Desktop.
VB.Net: Object to Dictionary
Public Function ToDictionary() As Dictionary(Of String, Object)
Dim dictionary As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
For Each property_info As Reflection.PropertyInfo In [GetType].GetProperties()
Try
Console.WriteLine("name: " + property_info.Name + " value: " + property_info.GetValue(Me, Nothing).ToString)
dictionary.Add(property_info.Name, property_info.GetValue(Me, Nothing).ToString)
Catch ex As Exception
dictionary.Add(property_info.Name, ex.Message)
End Try
Next
Return dictionary
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment