private List <TypeEntry> Parse(DTEObject root)
        {
            List <TypeEntry> entries = new List <TypeEntry>();

            var entities = root.GetEntities();

            foreach (var entity in entities)
            {
                var value = entity as DTEValue;
                if (value != null)
                {
                    entries.Add(CreateEntry(value));
                    continue;
                }

                var obj = entity as DTEObject;
                if (obj != null)
                {
                    entries.Add(CreateEntry(obj));
                    continue;
                }

                var list = entity as DTEList;
                if (list != null)
                {
                    entries.Add(CreateEntry(list));
                    continue;
                }
            }

            return(entries);
        }
        public void SetObject(string findExp, DTObject obj)
        {
            ValidateReadOnly();

            if (string.IsNullOrEmpty(findExp))
            {
                //dto.Set(newDTO) 这种表达式下说明此时需要替换整个dto
                //为了保证数据安全,需要克隆,{xxx:{a,b}},如果不克隆,那么b=xxx就会出现错误
                var newRoot = obj.GetRoot().Clone() as DTEObject;
                newRoot.Parent = _root.Parent;
                _root          = newRoot;
            }
            else
            {
                DTEObject entity = FindEntity <DTEObject>(findExp, false);
                if (entity == null)
                {
                    var query = QueryExpression.Create(findExp);
                    _root.SetEntity(query, (name) =>
                    {
                        var e  = obj.GetRoot().Clone();
                        e.Name = name;
                        return(e);
                    });
                }
            }
        }
        private TypeEntry CreateEntry(DTEObject e)
        {
            var    name         = e.Name; //条目名称
            var    metadataCode = e.GetCode(false);
            string typeName     = GetPathName(name);

            return(new ObjectEntry(this, name, typeName, metadataCode));
        }
        public static DTObject CreateObject(DTEObject root, bool isReadOnly, bool isPinned)
        {
            var obj = isPinned ? new DTObject() : Symbiosis.TryMark(_objectPool, () =>
            {
                return(new DTObject());
            });

            obj._root      = root;
            obj.IsReadOnly = isReadOnly;
            obj.IsPinned   = isPinned;
            return(obj);
        }
Exemple #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;
        }
Exemple #6
0
        private static bool ContainsSchemaCode(DTEObject source, DTEObject target)
        {
            var es = target.GetEntities();

            foreach (var e in es)
            {
                var se = source.Find(e.Name);
                if (se == null)
                {
                    return(false);            //源中没有找到成员
                }
                var obj = e as DTEObject;
                if (obj != null)
                {
                    //对比子项
                    var sObj = se as DTEObject;
                    if (sObj == null)
                    {
                        return(false);              //类型不同
                    }
                    if (!ContainsSchemaCode(sObj, obj))
                    {
                        return(false);
                    }
                }
                else
                {
                    var list = e as DTEList;
                    if (list != null)
                    {
                        //对比子项
                        var sList = se as DTEList;
                        if (sList == null)
                        {
                            return(false);               //类型不同
                        }
                        if (!list.ItemTemplate.ContainsSchemaCode(sList.ItemTemplate))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
 /// <summary>
 /// 清理数据,提供池使用
 /// </summary>
 internal void Clear()
 {
     _root           = null;
     this.IsReadOnly = false;
 }