コード例 #1
0
 public void CallSerialize(byte value)
 {
     if (Config.IsIntegerToHex)
     {
         CharStream.WriteJsonHex(value);
     }
     else
     {
         AutoCSer.Extensions.NumberExtension.ToString(value, CharStream);
     }
 }
コード例 #2
0
 public void CallSerialize(uint value)
 {
     if (value <= ushort.MaxValue)
     {
         CallSerialize((ushort)value);
     }
     else if (Config.IsIntegerToHex)
     {
         CharStream.WriteJsonHex(value);
     }
     else
     {
         AutoCSer.Extensions.NumberExtension.ToString(value, CharStream);
     }
 }
コード例 #3
0
 public void CallSerialize(ulong value)
 {
     if (value <= MaxInteger || !Config.IsMaxNumberToString)
     {
         if (value <= uint.MaxValue)
         {
             CallSerialize((uint)value);
         }
         else if (Config.IsIntegerToHex)
         {
             CharStream.WriteJsonHex(value);
         }
         else
         {
             AutoCSer.Extensions.NumberExtension.ToString(value, CharStream);
         }
     }
     else
     {
         CharStream.WriteJsonString(value);
     }
 }
コード例 #4
0
ファイル: JsonSerializer.cs プロジェクト: AutoCSer/AutoCSer
        /// <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);
        }