public void CallSerialize(DateTime value) { CharStream.PrepCharSize(AutoCSer.Date.MillisecondStringSize); Date.ToMillisecondString(value, CharStream); }
/// <summary> /// 进入对象节点 /// </summary> /// <typeparam name="valueType">对象类型</typeparam> /// <param name="value">数据对象</param> /// <returns>是否继续处理对象</returns> private bool pushArray <valueType>(valueType value) { if (checkLoopDepth == 0) { if (forefatherCount != 0) { int count = forefatherCount; object objectValue = value; foreach (object arrayValue in forefather) { if (arrayValue == objectValue) { CharStream.WriteJsonObject(); return(false); } if (--count == 0) { break; } } } if (forefatherCount == forefather.Length) { forefather = forefather.copyNew(forefatherCount << 1); } forefather[forefatherCount++] = value; } else { if (--checkLoopDepth == 0) { throw new OverflowException(); } #if AutoCSer if (isLoopObject) { int index; if (objectIndexs.TryGetValue(new ObjectReference { Value = value }, out index)) { CharStream.PrepCharSize(Config.GetLoopObject.Length + (10 + 5 + 3)); CharStream.Data.SimpleWrite(Config.GetLoopObject); CharStream.Data.Write('('); CharStream.WriteJsonHex((uint)index); CharStream.Data.Write(',' + ('[' << 16) + ((long)']' << 32) + ((long)')' << 48)); return(false); } objectIndexs.Set(new ObjectReference { Value = value }, index = objectIndexs.Count); CharStream.PrepCharSize(Config.SetLoopObject.Length + (10 + 2 + 2)); CharStream.Data.SimpleWrite(Config.SetLoopObject); CharStream.Data.Write('('); CharStream.WriteJsonHex((uint)index); CharStream.Data.Write(','); } #endif } return(true); }
/// <summary> /// /// </summary> /// <param name="value"></param> private void serialize(ref Node value) { switch (value.Type) { case NodeType.Dictionary: CharStream.Write('{'); if ((int)value.Int64 != 0) { KeyValue <Node, Node>[] array = value.DictionaryArray; for (int index = 0; index != (int)value.Int64; ++index) { if (index != 0) { CharStream.Write(','); } serialize(ref array[index].Key); CharStream.Write(':'); serialize(ref array[index].Value); } } CharStream.Write('}'); return; case NodeType.Array: CharStream.Write('['); if ((int)value.Int64 != 0) { Node[] array = value.ListArray; for (int index = 0; index != (int)value.Int64; ++index) { if (index != 0) { CharStream.Write(','); } serialize(ref array[index]); CharStream.Write(':'); serialize(ref array[index]); } } CharStream.Write(']'); return; case NodeType.String: { SubString subString = value.SubString; CharStream.WriteJson(ref subString, Config.NullChar); } return; case NodeType.QuoteString: case NodeType.ErrorQuoteString: CharStream.PrepCharSize(value.SubString.Length + 2); CharStream.Data.Write((char)value.Int64); CharStream.Write(ref value.SubString); CharStream.Data.Write((char)value.Int64); return; case NodeType.NumberString: if ((int)value.Int64 == 0) { CharStream.Write(ref value.SubString); } else { CharStream.PrepCharSize(value.SubString.Length + 2); CharStream.Data.Write((char)value.Int64); CharStream.Write(ref value.SubString); CharStream.Data.Write((char)value.Int64); } return; case NodeType.Bool: CallSerialize((int)value.Int64 != 0); return; case NodeType.DateTimeTick: CallSerialize(new DateTime(value.Int64, DateTimeKind.Local)); return; case NodeType.NaN: CharStream.WriteJsonNaN(); return; case NodeType.PositiveInfinity: if (Config.IsInfinityToNaN) { CharStream.WriteJsonNaN(); } else { CharStream.WritePositiveInfinity(); } return; case NodeType.NegativeInfinity: if (Config.IsInfinityToNaN) { CharStream.WriteJsonNaN(); } else { CharStream.WriteNegativeInfinity(); } return; default: CharStream.WriteJsonNull(); return; } }