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(); }
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(); }
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 WriteValue(JsonWriter writer, object instance, IJsonSerializeOperationInfo info) { var value = _getValue(instance); writer.WriteValue(Name); writer.WriteNameValueSeparator(); _serializer.Value.SerializeObject(writer, value, 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 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(); }