private static void WriteObject(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Type     valueType     = value.GetType();
            TypeInfo valueTypeInfo = valueType.GetTypeInfo();

            writer.WriteStartObject();

            writer.WritePropertyName("$type");
            writer.WriteValue(NameUtility.GetSimpleAssemblyQualifiedName(valueType));

            writer.WritePropertyName("$value");

            if (valueTypeInfo.IsPrimitive)
            {
                writer.WriteValue(value);
            }
            else
            {
                serializer.Serialize(writer, value);
            }

            writer.WriteEndObject();
        }