public void CallSerialize(object value)
 {
     if (value == null)
     {
         CharStream.WriteJsonNull();
     }
     else if (value.GetType() == typeof(Node))
     {
         CallSerialize((Node)value);
     }
     else if (Config.IsObject)
     {
         Type type = value.GetType();
         if (type == typeof(object))
         {
             CharStream.WriteJsonObject();
         }
         //else SerializeMethodCache.GetObject(type)(this, value);
         else
         {
             GenericType.Get(type).JsonSerializeObjectDelegate(this, value);
         }
     }
     else
     {
         CharStream.WriteJsonObject();
     }
 }
Example #2
0
        /// <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);
        }