Exemplo n.º 1
0
        /// <summary>
        /// 向集合追加一个成员
        /// </summary>
        /// <param name="findExp"></param>
        /// <param name="member"></param>
        public void Push(string findExp, DTObject member)
        {
            ValidateReadOnly();

            DTEList entity = FindEntity <DTEList>(findExp, false);

            if (entity == null)
            {
                var query = QueryExpression.Create(findExp);
                _root.SetEntity(query, (name) =>
                {
                    var dte  = DTOPool.CreateDTEList(this.IsPinned);
                    dte.Name = name;
                    return(dte);
                });
                entity = FindEntity <DTEList>(findExp, true);
            }
            ;
            if (member == null)
            {
                return;
            }

            entity.Push(member);
        }
Exemplo n.º 2
0
        private DTEList CreateListEntity(string name, IEnumerable list)
        {
            var dte = DTOPool.CreateDTEList(this.IsPinned);

            dte.Name = name;

            foreach (var item in list)
            {
                dte.CreateAndPush((dto) =>
                {
                    dto.SetValue(item);
                });
            }
            return(dte);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        private DTEList GetOrCreateList(string findExp)
        {
            DTEList entity = FindEntity <DTEList>(findExp, false);

            if (entity == null)
            {
                var query = QueryExpression.Create(findExp);
                _root.SetEntity(query, (name) =>
                {
                    var dte  = DTOPool.CreateDTEList(this.IsPinned);
                    dte.Name = name;
                    return(dte);
                });
                entity = FindEntity <DTEList>(findExp, true);
            }
            return(entity);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 如果不存在findExp对应的列表,那么创建
        /// </summary>
        /// <param name="findExp"></param>
        public void SetList(string findExp)
        {
            ValidateReadOnly();

            DTEList entity = FindEntity <DTEList>(findExp, false);

            if (entity == null)
            {
                var query = QueryExpression.Create(findExp);
                _root.SetEntity(query, (name) =>
                {
                    var dte  = DTOPool.CreateDTEList(this.IsPinned);
                    dte.Name = name;
                    return(dte);
                });
            }
            ;
        }
Exemplo n.º 6
0
 /// <summary>
 /// 仅克隆结构
 /// </summary>
 /// <returns></returns>
 public override DTEntity Clone()
 {
     return(DTOPool.CreateDTEList(this.Name, this.ItemTemplate, this.Items, this.IsPinned));
 }