internal static Nullable <T> CallNullableObjectInvoke <T>(IDeserializerReader reader, JsonDeserializeSetting setting, string name, int arrayLevel) where T : struct
        {
            if (reader.Count == 0)
            {
                return(null);
            }

            var node = reader.Read(name);

            if (node == null)
            {
                return(null);
            }

            var nodeValue = node.GetValue();

            if (node != null && StringMethodProvider.Default.IsNullValue(nodeValue))
            {
                return(null);
            }

            if (node != null && node.NodeType == ContentNodeType.Object)
            {
                return(ZzzZzDeserializerBuilder <T> .Register(setting).Invoke(reader.Parse(node), setting, arrayLevel));
            }

            return(ZzzZzDeserializerBuilder <T> .Register(setting).Invoke(reader, setting, arrayLevel));
        }
        /// <summary>
        /// 装载数据到字典中
        /// </summary>
        /// <typeparam name="V"></typeparam>
        /// <param name="dictionary">The result.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="setting">The setting.</param>
        /// <param name="name">The name.</param>
        /// <param name="arrayLevel"></param>
        public virtual void LoadStringKey <V>(IDictionary <string, V> dictionary, IDeserializerReader reader, JsonDeserializeSetting setting, string name, int arrayLevel)
        {
            var node = reader.Read(name);

            if (node == null)
            {
                if (name != null)
                {
                    return;
                }

                while (true)
                {
                    var item = reader.MoveNext();
                    if (item == null)
                    {
                        break;
                    }

                    var key = ZzzZzDeserializerBuilder <string> .Register(setting).Invoke(ThunderReader.Load(item.Key), setting, arrayLevel);

                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }

                    var value = ZzzZzDeserializerBuilder <V> .Register(setting).Invoke(reader.Parse(item), setting, arrayLevel);

                    dictionary[key] = value;
                }

                return;
            }

            if (node.NodeType == ContentNodeType.String)
            {
                return;
            }

            if (node.NodeType != ContentNodeType.Object)
            {
                throw new ArgumentException(string.Format("字典只能为key-value形式,当前形式为{0}", node.NodeType.ToString()));
            }

            foreach (var n in (IList <JsonContentNode>)node.Node)
            {
                var key = ZzzZzDeserializerBuilder <string> .Register(setting).Invoke(ThunderReader.Load(n.Key), setting, arrayLevel);

                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }

                var value = ZzzZzDeserializerBuilder <V> .Register(setting).Invoke(reader.Parse(n), setting, arrayLevel);

                dictionary[key] = value;
            }
        }
        internal static T CallObjectInvoke <T>(IDeserializerReader reader, JsonDeserializeSetting setting, string name, int arrayLevel)
        {
            var node = reader.Read(name);

            if (node == null)
            {
                return(default(T));
            }

            var nodeValue = node.GetValue();

            if (nodeValue != null && StringMethodProvider.Default.IsNullValue(nodeValue))
            {
                return(default(T));
            }

            return(ZzzZzDeserializerBuilder <T> .Register(setting).Invoke(reader.Parse(node), setting, arrayLevel));
        }
Exemple #4
0
        /// <summary>
        /// 在流中读取字节后转换为对象
        /// </summary>
        /// <param name="setting">配置项</param>
        /// <param name="reader">字节流内容读取器</param>
        /// <param name="name">名字</param>
        /// <returns>返回目标对象</returns>
        public T Parse(IDeserializerReader reader, JsonDeserializeSetting setting, string name)
        {
            var node = reader.Read(name);

            if (node == null)
            {
                if (reader.Count == 0)
                {
                    return(default(T));
                }

                return(ExceptionDeseralizerBuilder <T> .Register(setting).Invoke(reader, setting, 0));
            }

            if (node.NodeType != ContentNodeType.Object)
            {
                return(default(T));
            }

            return(ExceptionDeseralizerBuilder <T> .Register(setting).Invoke(reader.Parse(node), setting, 0));
        }
        /// <summary>
        /// 执行builder,反射用到的
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reader">The writer.</param>
        /// <param name="setting">The setting.</param>
        /// <param name="name"></param>
        /// <param name="arrayLevel">层次</param>
        internal static T CallBuilderInvoke <T>(IDeserializerReader reader, JsonDeserializeSetting setting, string name, int arrayLevel)
        {
            var @delegate = ZzzZzDeserializerBuilder <T> .Register(setting);

            return(name == null? @delegate.Invoke(reader, setting, arrayLevel) : @delegate.Invoke(reader.Parse(reader.Read(name)), setting, arrayLevel));
        }
Exemple #6
0
        /// <summary>
        /// 写入流中
        /// </summary>
        /// <param name="name">The writer.</param>
        /// <param name="setting">The setting.</param>
        /// <param name="reader">The array.</param>
        /// <param name="arrayLevel">下一个数组层次,如果为1,则表示数组连续,比如2维数据</param>
        public virtual T[] Parse(IDeserializerReader reader, JsonDeserializeSetting setting, string name, int arrayLevel)
        {
            var node = reader.Read(name);

            if (node == null)
            {
                if (name != null)
                {
                    return(new T[0]);
                }

                if (reader.ContainerSignal != ContainerSignal.Array)
                {
                    return(new T[0]);
                }

                var temp = new T[reader.Count];
                for (var i = 0; i < reader.Count; i++)
                {
                    var item = reader.MoveNext();
                    if (item == null)
                    {
                        break;
                    }

                    temp[i] = ZzzZzDeserializerBuilder <T> .Register(setting).Invoke(reader.Parse(item), setting, arrayLevel);
                }

                return(temp);
            }

            if (node.NodeType != ContentNodeType.Array)
            {
                return(new T[0]);
            }

            var nodes = node.Node as IList <JsonContentNode>;

            if (nodes == null)
            {
                return(new T[0]);
            }

            if (nodes.Count == 1)
            {
                var subNodes = nodes[0].Node as IList <JsonContentNode>;
                if (subNodes == null || subNodes.Count <= 0)
                {
                    var nodeValue = nodes[0] == null ? ArraySegmentValue.Empty : nodes[0].GetValue();
                    if (nodeValue.IsNullOrEmpty)
                    {
                        return(new T[0]);
                    }
                }
            }

            if (nodes[0].ArrayLevel != arrayLevel)
            {
                return(new T[0]);
            }

            var list = new T[nodes.Count];

            for (var i = 0; i < nodes.Count; i++)
            {
                var nodeValue = nodes[i] == null ? ArraySegmentValue.Empty : nodes[i].GetValue();
                if (nodes[i].NodeType == ContentNodeType.String)
                {
                    if (StringMethodProvider.Default.IsNullValue(nodeValue))
                    {
                        list[i] = default(T);
                        continue;
                    }
                }

                list[i] = ZzzZzDeserializerBuilder <T> .Register(setting).Invoke(reader.Parse(nodes[i]), setting, arrayLevel);
            }

            return(list);
        }