Beispiel #1
0
 public IEnumerable <DTEntity> GetSelfEntities()
 {
     if (_selfEntities == null)
     {
         var es = DTOPool.CreateDTEntities(this.IsPinned);
         es.Add(this);
         _selfEntities = es;
     }
     return(_selfEntities);
 }
Beispiel #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);
        }
Beispiel #3
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);
        }
        public override IEnumerable <DTEntity> FindEntities(QueryExpression query)
        {
            if (query.IsSelfEntities)
            {
                return(this.GetSelfEntities());                      //*代表返回对象自己
            }
            List <DTEntity> list = DTOPool.CreateDTEntities(this.IsPinned);

            foreach (var e in Items)
            {
                var es = e.GetRoot().FindEntities(query);
                list.AddRange(es);
            }
            return(list);
        }
Beispiel #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);
            }
        }
        internal DTEntity[] FindEntities(string findExp, bool throwError)
        {
            var query = QueryExpression.Create(findExp);

            List <DTEntity> list = DTOPool.CreateDTEntities(this.IsPinned);
            var             es   = _root.FindEntities(query);

            list.AddRange(es);

            if (list.Count == 0)
            {
                if (throwError)
                {
                    throw new NotFoundDTEntityException("没有找到" + findExp + "对应的DTO实体!");
                }
                return(list.ToArray());
            }
            return(list.ToArray());
        }
Beispiel #7
0
 public void Init(bool isPinned)
 {
     this.IsPinned = isPinned;
     this.SetMembers(DTOPool.CreateDTEntities(isPinned));
 }