Created
September 29, 2019 13:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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