public void SerializeObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { if (instance == null) { writer.WriteNull(); } else { var serializer = _serializerCache.GetOrAdd(Tuple.Create(instance.GetType(), _encrypt), tuple => GetSerializer(tuple.Item1)); if (_encrypt) { var toggler = new EncryptWritesToggler(writer); toggler.Toggle(); serializer.SerializeObject(writer, instance, info); toggler.Revert(); } else { serializer.SerializeObject(writer, instance, info); } } }
public void SerializeObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { if (instance == null) { writer.WriteNull(); } else { if (_encrypt) { var toggler = new EncryptWritesToggler(writer); toggler.Toggle(); _write(writer, instance); toggler.Revert(); } else { _write(writer, instance); } } }
private void Write(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { writer.WriteOpenArray(); var enumerable = (IEnumerable)instance; var first = true; foreach (var item in enumerable) { if (first) { first = false; } else { writer.WriteItemSeparator(); } _itemSerializer.SerializeObject(writer, item, info); } writer.WriteCloseArray(); }
public void SerializeObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { var jsonObject = (JsonObject)instance; writer.WriteOpenObject(); var first = true; foreach (var item in jsonObject) { if (first) { first = false; } else { writer.WriteItemSeparator(); } writer.WriteValue(item.Key); writer.WriteNameValueSeparator(); _dynamicJsonSerializer.SerializeObject(writer, item.Value, info); } writer.WriteCloseObject(); }
public void SerializeObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { var jsonArray = (JsonArray)instance; writer.WriteOpenArray(); var first = true; foreach (var item in jsonArray) { if (first) { first = false; } else { writer.WriteItemSeparator(); } _dynamicJsonSerializer.SerializeObject(writer, item, info); } writer.WriteCloseArray(); }
private void Write(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { writer.WriteOpenObject(); var first = true; var serializingProperties = _serializingPropertiesMap.GetOrAdd(instance.GetType(), GetSerializableProperties); foreach (var property in serializingProperties) { if (first) { first = false; } else { writer.WriteItemSeparator(); } property.WriteValue(writer, instance, info); } writer.WriteCloseObject(); }
public void WriteValue(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { var value = _getValue(instance); writer.WriteValue(Name); writer.WriteNameValueSeparator(); _serializer.Value.SerializeObject(writer, value, info); }
public void SerializeObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { _write(writer, instance, info); }
private void WriteIDictionaryOfAnythingToAnything(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { writer.WriteOpenObject(); var dictionary = (IEnumerable)instance; var first = true; Func<object, object> getKeyFunc = null; Func<object, object> getValueFunc = null; foreach (var item in dictionary) { if (first) { first = false; var itemType = item.GetType(); getKeyFunc = _getKeyFuncCache.GetOrAdd(itemType, GetGetKeyFunc); getValueFunc = _getValueFuncCache.GetOrAdd(itemType, GetGetValueFunc); } else { writer.WriteItemSeparator(); } var key = getKeyFunc(item); var keyString = key as string; if (keyString != null) { writer.WriteValue(keyString); } else { var sb = new StringBuilder(); using (var stringWriter = new StringWriterWithEncoding(sb, Encoding.UTF8)) { using (var keyWriter = new JsonWriter(stringWriter, info)) { _keySerializer.SerializeObject(keyWriter, key, info); } } writer.WriteValue((sb.ToString())); } writer.WriteNameValueSeparator(); _valueSerializer.SerializeObject(writer, getValueFunc(item), info); } writer.WriteCloseObject(); }
private void WriteIDictionaryOfStringToAnything(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { writer.WriteOpenObject(); var dictionary = (IEnumerable)instance; var first = true; Func<object, object> getKeyFunc = null; Func<object, object> getValueFunc = null; foreach (var item in dictionary) { if (first) { first = false; var itemType = item.GetType(); getKeyFunc = _getKeyFuncCache.GetOrAdd(itemType, GetGetKeyFunc); getValueFunc = _getValueFuncCache.GetOrAdd(itemType, GetGetValueFunc); } else { writer.WriteItemSeparator(); } writer.WriteValue((string)getKeyFunc(item)); writer.WriteNameValueSeparator(); _valueSerializer.SerializeObject(writer, getValueFunc(item), info); } writer.WriteCloseObject(); }
private void WriteIDictionaryOfStringToObject(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { writer.WriteOpenObject(); var dictionary = (IDictionary<string, object>)instance; var first = true; foreach (var item in dictionary) { if (first) { first = false; } else { writer.WriteItemSeparator(); } writer.WriteValue(item.Key); writer.WriteNameValueSeparator(); _valueSerializer.SerializeObject(writer, item.Value, info); } writer.WriteCloseObject(); }