/// <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); }
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); }
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); } }
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); }
/// <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); }); } ; }
/// <summary> /// 仅克隆结构 /// </summary> /// <returns></returns> public override DTEntity Clone() { return(DTOPool.CreateDTEList(this.Name, this.ItemTemplate, this.Items, this.IsPinned)); }