Esempio n. 1
0
        /// <summary>
        /// 预处理节点代码
        /// </summary>
        /// <param name="nodeCode"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        private static NameAndValue PreHandle(CodeType parentCodeType, StringSegment nodeCode)
        {
            StringSegment name, value;
            var           code = nodeCode.Trim();

            if (CodeTreeNode.IsObject(code) || CodeTreeNode.IsList(code))
            {
                name  = StringSegment.Null;
                value = code;
            }
            else
            {
                int pos = code.IndexOf(':');
                if (parentCodeType == CodeType.Object)
                {
                    name  = pos == -1 ? code : code.Substring(0, pos).Trim();
                    value = pos == -1 ? StringSegment.Null : code.Substring(pos + 1).Trim();
                }
                else
                {
                    name  = pos == -1 ? StringSegment.Null : code.Substring(0, pos).Trim();
                    value = pos == -1 ? code : code.Substring(pos + 1).Trim();
                }
            }

            return(new NameAndValue(name, value));
        }
Esempio n. 2
0
        private static CodeTreeNode ParseNode(CodeType parentCodeType, StringSegment nodeCode)
        {
            var nv    = PreHandle(parentCodeType, nodeCode);
            var name  = nv.Name;
            var value = nv.Value;

            CodeTreeNode node;

            if (CodeTreeNode.IsObject(value))
            {
                value = TrimSign(value);
                var childs = ParseNodes(CodeType.Object, value);
                node = new CodeTreeNode(name, value, CodeType.Object, childs);
            }
            else if (CodeTreeNode.IsList(value))
            {
                value = TrimSign(value);
                var childs = ParseNodes(CodeType.List, value);
                node = new CodeTreeNode(name, value, CodeType.List, childs);
            }
            else
            {
                var codeType = CodeTreeNode.GetValueType(value);
                node = new CodeTreeNode(name, value, codeType);
            }
            return(node);
        }
Esempio n. 3
0
        /// <summary>
        /// 预处理节点代码
        /// </summary>
        /// <param name="nodeCode"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        private static NameAndValue PreHandle(CodeType parentCodeType, StringSegment nodeCode)
        {
            StringSegment name, value;
            var code = nodeCode.Trim();
            if (CodeTreeNode.IsObject(code) || CodeTreeNode.IsList(code))
            {
                name = StringSegment.Null;
                value = code;
            }
            else
            {
                var info = DeserializerUtil.Find(code, 0, ':');
                if (parentCodeType == CodeType.Object)
                {
                    name = !info.Finded ? code : code.Substring(0, info.KeyPosition).Trim();
                    value = !info.Finded ? StringSegment.Null : code.Substring(info.KeyPosition + 1).Trim();
                }
                else
                {
                    name = !info.Finded ? StringSegment.Null : code.Substring(0, info.KeyPosition).Trim();
                    value = !info.Finded ? code : code.Substring(info.KeyPosition + 1).Trim();
                }
            }

            return new NameAndValue(name, value);
        }
Esempio n. 4
0
 private static object GetNodeValue(CodeTreeNode node)
 {
     if(node.Type == CodeType.StringValue)
     {
         var value = JSON.GetStringValue(node.Value);
         Guid guid = Guid.Empty;
         if (Guid.TryParse(value, out guid)) return guid;
         return value;
     }
     return JSON.GetValue(node.Value);
 }
Esempio n. 5
0
        private static void FillEntities(List <DTEntity> entities, CodeTreeNode node, bool isReadOnly, bool isPinned)
        {
            var name = JSON.GetStringValue(node.Name.ToString());

            if (node.Type == CodeType.Object)
            {
                var members = DTOPool.CreateDTEntities(isPinned);
                //收集成员
                foreach (CodeTreeNode item in node.Childs)
                {
                    FillEntities(members, item, isReadOnly, isPinned);
                }

                var obj = DTOPool.CreateDTEObject(members, isPinned);
                obj.Name = name;
                entities.Add(obj);
            }
            else if (node.Type == CodeType.List)
            {
                var childs = DTOPool.CreateObjects(isPinned);
                using (var temp = DTOPool.EntitiesPool.Borrow())
                {
                    //收集成员
                    var tempChilds = temp.Item;
                    foreach (CodeTreeNode item in node.Childs)
                    {
                        FillEntities(tempChilds, item, isReadOnly, isPinned);
                    }

                    foreach (var e in tempChilds)
                    {
                        var item = CreateDTObject(e, isReadOnly, isPinned);
                        childs.Add(item);
                    }
                }

                var list = DTOPool.CreateDTEList(childs, isPinned);
                list.Name = name;
                entities.Add(list);
            }
            else
            {
                object value = node.Type == CodeType.StringValue ? JSON.GetStringValue(node.Value) : JSON.GetValue(node.Value);
                var    dte   = DTOPool.CreateDTEValue(name, value, isPinned);
                entities.Add(dte);
            }
        }