/// <summary> /// 写入流中 /// </summary> /// <param name="writer">The writer.</param> /// <param name="setting">The setting.</param> /// <param name="level"></param> /// <param name="array">The array.</param> public virtual void Write(ISerializerWriter writer, JsonSerializeSetting setting, byte level, IEnumerable array) { if (array == null) { if (setting.WriteNullWhenObjectIsNull) { writer.Write("null"); } else { writer.Write("[]"); } return; } writer.Write("["); var enumerator = array.GetEnumerator(); bool moveNext = enumerator.MoveNext(); while (moveNext) { var item = enumerator.Current; SerialierBuilderHelper.QueryBuilderInvoker(item.GetType())(writer, setting, item, level++); if (moveNext = enumerator.MoveNext()) { writer.Write(","); } } writer.Write("]"); return; }
/// <summary> /// 写入流中 /// </summary> /// <param name="writer">The writer.</param> /// <param name="setting">The setting.</param> /// <param name="level"></param> /// <param name="array">The array.</param> public virtual void WriteObjectValue(ISerializerWriter writer, JsonSerializeSetting setting, byte level, IDictionary <Key, object> array) { if (array == null) { if (setting.WriteNullWhenObjectIsNull) { writer.Write("null"); } else { writer.Write("{}"); } return; } if (array.Count == 0) { writer.Write("{}"); return; } writer.Write("{"); var i = -1; foreach (var a in array) { i++; ZzzZzSerialierBuilder <Key> .Register(setting).Invoke(writer, setting, a.Key, level++); writer.Write(":"); if (a.Value == null) { if (setting.WriteNullWhenObjectIsNull) { writer.Write("null"); } else { writer.Write("{}"); } } else { SerialierBuilderHelper.QueryBuilderInvoker(a.Value.GetType()).Invoke(writer, setting, a.Value, level++); } if (i < array.Count - 1) { writer.Write(","); } } writer.Write("}"); return; }
/// <summary> /// 序列化对象 /// </summary> /// <param name="object">源对象</param> /// <param name="setting">配置</param> /// <param name="writer">写入流</param> /// <returns></returns> private static void Serialize(object @object, JsonSerializeSetting setting, ISerializerWriter writer) { if (@object == null) { writer.Write("null"); return; } var @delegate = SerialierBuilderHelper.QueryBuilderInvoker(@object.GetType()); @delegate(writer, setting, @object, 0); }
/// <summary> /// 写入流中 /// </summary> /// <param name="writer">The writer.</param> /// <param name="setting">The setting.</param> /// <param name="level"></param> /// <param name="array">The array.</param> public virtual void Write(ISerializerWriter writer, JsonSerializeSetting setting, byte level, IDictionary array) { if (array == null) { if (setting.WriteNullWhenObjectIsNull) { writer.Write("null"); } else { writer.Write("{}"); } return; } if (array.Count == 0) { writer.Write("{}"); return; } writer.Write("{"); var enumerator = array.Keys.GetEnumerator(); bool moveNext = enumerator.MoveNext(); while (moveNext) { SerialierBuilderHelper.QueryBuilderInvoker(enumerator.Current.GetType())(writer, setting, enumerator.Current, level++); writer.Write(":"); var item = array[enumerator.Current]; SerialierBuilderHelper.QueryBuilderInvoker(item.GetType())(writer, setting, item, level++); if (moveNext = enumerator.MoveNext()) { writer.Write(","); } } writer.Write("}"); return; }
/// <summary> /// 写入流中 /// </summary> /// <param name="writer">The writer.</param> /// <param name="setting">The setting.</param> /// <param name="array">The array.</param> /// <param name="level"></param> public virtual void Write(ISerializerWriter writer, JsonSerializeSetting setting, byte level, IEnumerable <object> array) { if (array == null) { if (setting.WriteNullWhenObjectIsNull) { writer.Write("null"); } else { writer.Write("[]"); } return; } var list = array as IList <object>; if (list != null) { writer.Write("["); for (var i = 0; i < list.Count; i++) { var item = list[i]; var @str = item as string; if (str != null) { ZzzZzSerialierBuilder <string> .Register(setting).Invoke(writer, setting, @str, level++); if (i < list.Count - 1) { writer.Write(","); } continue; } var inlineArray = item as IEnumerable; if (inlineArray != null) { writer.Write("["); var listEnumerator = inlineArray.GetEnumerator(); if (listEnumerator.MoveNext()) { if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } while (listEnumerator.MoveNext()) { writer.Write(","); if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } writer.Write("]"); if (i < list.Count - 1) { writer.Write(","); } continue; } if (item != null) { SerialierBuilderHelper.QueryBuilderInvoker(item.GetType())(writer, setting, item, level++); } else { writer.Write("null"); } if (i < list.Count - 1) { writer.Write(","); } continue; } writer.Write("]"); return; } writer.Write("["); var enumerator = array.GetEnumerator(); if (enumerator.MoveNext()) { var @str = enumerator.Current as string; if (str != null) { ZzzZzSerialierBuilder <string> .Register(setting).Invoke(writer, setting, @str, level++); } else { var inlineArray = enumerator.Current as IEnumerable; if (inlineArray != null) { writer.Write("["); var listEnumerator = inlineArray.GetEnumerator(); if (listEnumerator.MoveNext()) { if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } while (listEnumerator.MoveNext()) { writer.Write(","); if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } writer.Write("]"); } else { if (enumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(enumerator.Current.GetType())(writer, setting, enumerator.Current, level++); } } } } while (enumerator.MoveNext()) { writer.Write(","); var @str = enumerator.Current as string; if (str != null) { ZzzZzSerialierBuilder <string> .Register(setting).Invoke(writer, setting, @str, level++); } else { var inlineArray = enumerator.Current as IEnumerable; if (inlineArray != null) { writer.Write("["); var listEnumerator = inlineArray.GetEnumerator(); if (listEnumerator.MoveNext()) { if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } while (listEnumerator.MoveNext()) { writer.Write(","); if (listEnumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(listEnumerator.Current.GetType())(writer, setting, listEnumerator.Current, level++); } } writer.Write("]"); } else { if (enumerator.Current == null) { writer.Write("null"); } else { SerialierBuilderHelper.QueryBuilderInvoker(enumerator.Current.GetType())(writer, setting, enumerator.Current, level++); } } } } writer.Write("]"); return; }