/// <summary> /// Serializes using custom methods (JsonAdaptor, IJsonable, Type serializer). /// </summary> private void SerializeCustomData(object data) { Type dataType = data.GetType(); JsonObject serializedData = null; // Serialize objects registered to adaptor. serializedData = JsonAdaptor.Serialize(dataType, data); if (serializedData != null) { SerializeObject(serializedData); return; } // Serialize jsonable objects IJsonable jsonableObject = data as IJsonable; if (jsonableObject != null) { serializedData = jsonableObject.ToJsonObject(); if (serializedData != null) { SerializeObject(jsonableObject.ToJsonObject()); return; } } // Use reflection. serializedData = JsonTypeSerializer.Serialize(dataType, data); if (serializedData != null) { SerializeObject(serializedData); return; } //This is when all the above methods fail. //Just return the stringified data. sb.Append('"'); AppendEscapedString(data.ToString()); sb.Append('"'); }