Calling this (note I HAVE commented some bit out and added an unconditional else for class types at line 72)
Public Shared Function get_JSON(o as Object, onlyPrefixed as boolean, compact as boolean) as JSONItem
Const kPrefix = ""
//runs through all the j_ properties for this record and returns the appropriate JSONItem and sub-items.
//each jsonItem created herein is added as a child to top via top.value( pi.name ) = pi.value
//except arrays, where each element in the array is added via an .append
If o = Nil Then
Return Nil
End If
Dim js As New JSONItem
js.Compact = compact
Dim ti As Introspection.TypeInfo = Introspection.GetType(o)
Dim props() As Introspection.PropertyInfo = ti.GetProperties
For Each pi As Introspection.PropertyInfo In props
//this works for non-array properties - and string values - but not others - need to test for different types of property.
//use typeInfo
//test
'If IsMarkedJSON(pi, True) Then
'If pi.name = "j_dupes" Then Break
'End If
Dim pt As Introspection.TypeInfo = pi.PropertyType
Dim n As String = Replace( pi.name, kPrefix, "")
Dim key As String = pt.FullName
Dim isMarked As Boolean = IsMarkedJSON(pi, onlyPrefixed)
If pt.isprimitive And IsMarked Then //only create values if needed
js.value(n) = get_JSON_primitive(o, pi)
Elseif pt.IsEnum And IsMarked Then
js.value(n) = pi.Value(o)
elseif pt.IsClass then
If pt.name = "Date" And IsMarked Then //date is a class, and prepended with j_
Dim d As date = pi.value(o).DateValue
If d <> Nil Then
js.value(n) = get_json(d, False, compact) //get all properties for date
End If
Elseif pt.name = "DateTime" And isMarked Then
Dim d As dateTime = pi.value(o).DateTimeValue
If d <> Nil Then
js.value(n) = get_json(d, False, compact) //get all properties for date
End If
Elseif pt.name = "jsonDictionary" And IsMarked Then
Break
// //get all the dictionary key and values
// //this gets the properties for dictionary - BinCount and Count - but doesn't get the key/value pairs
// Dim di As jsonDictionary = pi.value(o)
// If di = Nil Then Continue //empty dictionary
// di.setProp_values //this sets properties based on keys and values
//
// If di <> Nil Then
// js.value(n) = get_json(di, onlyPrefixed, compact) //this gets the properties for dictionary which should now include j_keys and j_values
// End If
// Elseif diClasses.haskey(key) Then //only if the class is registered
Else
js.value(n) = get_json(pi.Value(o), onlyPrefixed, compact)
End If
Elseif pt.IsArray And IsMarked Then
//each array is addressed at this level
//only arrays of primitives or json classes are addressed at the next level
Break
'js.value(n) = get_JSON_array( o, pi, onlyPrefixed, compact)
Elseif IsMarked Then
Break
end
next
return js
End Function
with
Dim d As datetime = DateTime.Now
Dim j As JSONItem = get_JSON(d, False, False)
Dim s As String = j.ToString
break
I get
{
"Day":17,
"DayOfWeek":4,
"DayOfYear":169,
"Hour":13,
"IsDaylightSavingsTime":true,
"Minute":34,
"Month":6,
"Nanosecond":856222152,
"Second":49,
"SecondsFrom1970":1592422489.856222152709961,
"SQLDate":"2020-06-17",
"SQLDateTime":"2020-06-17 13:34:49",
"Timezone":{
"Abbreviation":"America\\/Edmonton",
"SecondsFromGMT":-21600
},
"WeekOfYear":25,
"Year":2020
}
which now includes the TZ