I need to make sure type information is included in an object serialized via a custom JsonConverter.
The WriteJson method receives a JsonWriter and a JsonSerializer as parameters, but I cannot figure out how I can ensure the "$type" member is written. I think this should be done automatially based on the serializer's settings, but there is no apparent way to do so.
I could write the property manually using JObject's WritePropertyName and WriteValue methods, but in that case I'd have to check the serializer's settings myself, and furthermore I'd have to process other settings such as the "Simple" assembly format option and strip the version info off the assembly myself after calling Binder.BindToName.
If you were to make the ReflectionUtils class public rather than internal, I could call its GetTypeName method which shortens the assembly name based on the assembly format passed to it. As it stands, I have no way to ensuring the serializer's settings for embedding type information are honored in a custom JsonConverter, unless there is some way to construct a JObject that involves using the serializer settings before writing it to the JsonWriter.
Comments: ** Comment from web user: triynko **
The WriteJson method receives a JsonWriter and a JsonSerializer as parameters, but I cannot figure out how I can ensure the "$type" member is written. I think this should be done automatially based on the serializer's settings, but there is no apparent way to do so.
I could write the property manually using JObject's WritePropertyName and WriteValue methods, but in that case I'd have to check the serializer's settings myself, and furthermore I'd have to process other settings such as the "Simple" assembly format option and strip the version info off the assembly myself after calling Binder.BindToName.
If you were to make the ReflectionUtils class public rather than internal, I could call its GetTypeName method which shortens the assembly name based on the assembly format passed to it. As it stands, I have no way to ensuring the serializer's settings for embedding type information are honored in a custom JsonConverter, unless there is some way to construct a JObject that involves using the serializer settings before writing it to the JsonWriter.
Comments: ** Comment from web user: triynko **
Nope, that's doesn't work either. Looks like the final "type" parameter in the serialized call is ignored. Still no way to embed type information.