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 void SetValue(DTEntity target, object value, string findExp) { var parent = target.Parent as DTEObject; if (parent == null) { throw new DTOException("表达式错误" + findExp); } var query = QueryExpression.Create(target.Name); parent.SetEntity(query, (name) => { var dtoValue = value as DTObject; if (dtoValue != null) { var t = dtoValue.Clone(); var newEntity = t.GetRoot(); newEntity.Name = name; return(newEntity); } else { DTObject t = DTObject.CreateReusable(); t.SetValue(value); var newEntity = t.GetRoot().GetFirstEntity(); if (newEntity == null) { throw new DTOException("预期之外的错误," + findExp); } newEntity.Name = name; return(newEntity); } }); }
private void RetainEntities(DTObject dto, string[] findExps) { if (findExps.Length == 0) { return; } //收集需要保留的实体 var targets = new List <ReservedInfo>(); foreach (var findExp in findExps) { var items = dto.FindEntities(findExp, false); foreach (var item in items) { targets.Add(new ReservedInfo(item, true)); //加入自身 //再加入父亲,由于自身需要保留,所以父亲也得保留 var parent = item.Parent; while (parent != null) { targets.Add(new ReservedInfo(parent, false)); parent = parent.Parent; } } } targets = targets.Distinct().ToList(); //过滤重复 var removes = new List <DTEntity>(); CollectNeedRemove(dto.GetRoot().GetEntities(), targets, removes); foreach (var t in removes) { var parent = t.Parent; if (parent == null) { throw new DTOException("预期之外的错误," + string.Join(";", findExps)); } parent.DeletEntity(t); } }
/// <summary> /// 对象是否包含<paramref name="target"/>的架构代码 /// </summary> /// <param name="target"></param> /// <returns></returns> internal bool ContainsSchemaCode(DTObject target) { return(ContainsSchemaCode(this.GetRoot(), target.GetRoot())); }