Example #1
0
 public static DTEObject Deserialize(string code, bool isReadOnly, bool isPinned)
 {
     if (string.IsNullOrEmpty(code))
     {
         return(DTOPool.CreateDTEObject(isPinned));
     }
     return(Deserialize(new StringSegment(code), isReadOnly, isPinned));
 }
Example #2
0
        private static DTObject CreateDTObject(DTEntity root, bool isReadOnly, bool isPinned)
        {
            var o = root as DTEObject;
            if (o != null) return DTOPool.CreateObject(o, isReadOnly, isPinned);

            var members = DTOPool.CreateDTEntities(isPinned);
            members.Add(root);

            o = DTOPool.CreateDTEObject(members, isPinned);
            return DTOPool.CreateObject(o, isReadOnly, isPinned);
        }
Example #3
0
        /// <summary>
        /// 设置成员,当成员存在时覆盖,成员不存在时新增
        /// </summary>
        /// <param name="findExp"></param>
        /// <param name="value"></param>
        public override void SetEntity(QueryExpression query, Func <string, DTEntity> createEntity)
        {
            var segment = query.Segment;

            var entity = _entities.FirstOrDefault((m) =>
            {
                return(m.Name.Equals(segment, StringComparison.OrdinalIgnoreCase));
            });

            if (entity != null)
            {
                if (query.Next == null)
                {
                    //覆盖,此处并没有改变name
                    var index = _entities.IndexOf(entity);
                    var e     = createEntity(segment);
                    e.Parent         = this;
                    _entities[index] = e;
                    Changed();
                }
                else
                {
                    //由于表达式还未完,所以在下个节点中继续执行
                    entity.SetEntity(query.Next, createEntity);
                }
            }
            else
            {
                //没有找到
                if (query.Next == null)
                {
                    //没有后续
                    var e = createEntity(segment);
                    e.Parent = this;
                    _entities.Add(e);
                    //OrderSelfMembers(); //重新排序
                    Changed();
                }
                else
                {
                    var next = DTOPool.CreateDTEObject(this.IsPinned);
                    next.Name   = segment;
                    next.Parent = this;
                    _entities.Add(next);
                    //OrderSelfMembers(); //重新排序
                    Changed();

                    next.SetEntity(query.Next, createEntity);
                }
            }
        }
Example #4
0
        /// <summary>
        /// 仅克隆结构
        /// </summary>
        /// <returns></returns>
        public override DTEntity Clone()
        {
            var copy = DTOPool.CreateDTEntities(this.IsPinned);

            for (var i = 0; i < _entities.Count; i++)
            {
                copy.Add(_entities[i].Clone());
            }

            var dte = DTOPool.CreateDTEObject(copy, this.IsPinned);

            dte.Name = this.Name;
            return(dte);
        }
Example #5
0
        private static DTEObject Deserialize(StringSegment code, bool isReadOnly, bool isPinned)
        {
            if (code.IsEmpty()) return DTOPool.CreateDTEObject(isPinned);
            var node = ParseNode(CodeType.Object, code);

            DTEObject result = null;
            using (var temp = DTOPool.EntitiesPool.Borrow())
            {
                List<DTEntity> entities = temp.Item;
                FillEntities(entities, node, isReadOnly, isPinned);
                result = entities.First() as DTEObject;
            }
            return result;
        }
Example #6
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);
            }
        }