Пример #1
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);
            }
        }
Пример #2
0
        private DTEntity CreateEntity(string name, object value)
        {
            if (IsList(value))
            {
                var list = value as IEnumerable;
                if (list != null)
                {
                    return(CreateListEntity(name, list));
                }
            }

            var dto = value as DTObject;

            if (dto != null)
            {
                var root = dto.GetRoot();
                root.Name = name;
                return(root);
            }
            else
            {
                return(DTOPool.CreateDTEValue(name, value, this.IsPinned));
            }
        }
Пример #3
0
 /// <summary>
 /// 克隆
 /// </summary>
 /// <returns></returns>
 public override DTEntity Clone()
 {
     return(DTOPool.CreateDTEValue(this.Name, Clone(this.Value), this.IsPinned));
 }