Skip to content

Instantly share code, notes, and snippets.

@examinedliving
Created September 29, 2019 13:03
Show Gist options
  • Select an option

  • Save examinedliving/309d5560916ac9e3827557230d20e6a2 to your computer and use it in GitHub Desktop.

Select an option

Save examinedliving/309d5560916ac9e3827557230d20e6a2 to your computer and use it in GitHub Desktop.
Uses reflection to Get Class Instance Properties give "obj" is instance of class, returns a JSON key-value string of all properties of class.
Public Function GetPropertyValues(obj As Object) As String
Dim json As JObject = JObject.Parse("{}")
Dim t As Type = obj.GetType()
Dim props() As Reflection.PropertyInfo = t.GetProperties()
For Each prop In props
If prop.GetIndexParameters().Length = 0 Then
json.Item(prop.Name) = JToken.FromObject(prop.GetValue(obj, Nothing))
End If
Next
Return JsonConvert.SerializeObject(json, New Converters.KeyValuePairConverter())
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment