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 object GetValue(DTEntity e, Func <object, object> transformValue, bool isReadOnly) { var ve = e as DTEValue; if (ve != null) { return(transformValue(ve.Value)); } var le = e as DTEList; if (le != null) { var list = le.GetObjects(); var value = list.Select((item) => { if (item.IsSingleValue) { return(item.GetValue()); } return(item); }).ToArray(); return(transformValue(value)); } var oe = e as DTEObject; if (oe != null) { var value = DTOPool.CreateObject(oe, isReadOnly, oe.IsPinned); return(transformValue(value)); } return(null); }
public object GetValue(string findExp, bool throwError) { DTEntity entity = FindEntity(findExp, throwError); if (entity == null) { return(null); } return(GetValue(entity)); }
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); }
//internal T[] FindEntities<T>(string findExp, bool throwError) where T : DTEntity //{ // List<T> list = new List<T>(); // var query = QueryExpression.Create(findExp); // var es = _root.FindEntities(query); // foreach (var e in es) // { // var temp = e as T; // if (temp != null) list.Add(temp); // } // if (list.Count == 0) // { // if (throwError) // throw new NotFoundDTEntityException("没有找到" + findExp + "对应的DTO实体!"); // return list.ToArray(); // } // return list.ToArray(); //} private T FindEntity <T>(string findExp, bool throwError) where T : DTEntity { DTEntity e = FindEntity(findExp, throwError); if (e == null) { return(null); } T entity = e as T; if (entity == null && throwError) { throw new DTOTypeErrorException("表达式" + findExp + "对应的DTO不是" + typeof(T).FullName + "!"); } return(entity); }
public override void DeletEntity(DTEntity entity) { DTObject taget = null; foreach (var child in Items) { if (child.GetRoot() == entity) { taget = child; break; } } if (taget != null) { Items.Remove(taget); } this.Changed(); }
public object GetValue(string findExp, bool throwError) { DTEntity entity = FindEntity(findExp, throwError); if (entity == null) { return(null); } switch (entity.Type) { case DTEntityType.Value: { var ev = entity as DTEValue; if (ev != null) { return(ev.Value); } } break; case DTEntityType.Object: { var eo = entity as DTEObject; if (eo != null) { return(DTOPool.CreateObject(eo, this.IsReadOnly, this.IsPinned)); } } break; case DTEntityType.List: { var el = entity as DTEList; if (el != null) { return(el.GetObjects()); } } break; } return(null); }
internal DTEntity FindEntity(string findExp, bool throwError) { var query = QueryExpression.Create(findExp); DTEntity entity = null; var es = _root.FindEntities(query); if (es.Count() > 0) { entity = es.First(); } if (entity == null) { if (throwError) { throw new NotFoundDTEntityException("没有找到" + findExp + "对应的DTO实体!"); } return(null); } return(entity); }
//public Dictionary<string, T> GetDictionary<T>() //{ // return GetDictionary<T>(string.Empty, false); //} //public Dictionary<string, T> GetDictionary<T>(string findExp) //{ // return GetDictionary<T>(findExp, false); //} ///// <summary> ///// 本质上来说,json就是一组键值对,因此可以获取键值对形式的值 ///// </summary> ///// <typeparam name="T"></typeparam> ///// <param name="findExp"></param> ///// <param name="throwError"></param> ///// <returns></returns> //public Dictionary<string, T> GetDictionary<T>(string findExp, bool throwError) //{ // var entities = this.FindEntities(findExp, throwError); // var dictionary = new Dictionary<string, T>(entities.Length); // foreach (var entity in entities) // { // var key = entity.Name; // var value = CreateEntityValue(entity); // if (value is T) // dictionary.Add(key, (T)value); // } // return dictionary; //} private object CreateEntityValue(DTEntity entity) { switch (entity.Type) { case DTEntityType.Value: { var temp = entity as DTEValue; if (temp != null) { return(temp.Value); } } break; case DTEntityType.Object: { var temp = entity as DTEObject; if (temp != null) { return(DTOPool.CreateObject(temp, this.IsReadOnly, this.IsPinned)); } } break; case DTEntityType.List: { var temp = entity as DTEList; if (temp != null) { return(temp.GetObjects()); } } break; } throw new DTOException("在CreateEntityValue发生未知的错误,entity类型为" + entity.GetType()); }
private object GetValue(DTEntity entity) { switch (entity.Type) { case DTEntityType.Value: { var ev = entity as DTEValue; if (ev != null) { return(ev.Value); } } break; case DTEntityType.Object: { var eo = entity as DTEObject; if (eo != null) { return(DTOPool.CreateObject(eo, this.IsReadOnly, this.IsPinned)); } } break; case DTEntityType.List: { var el = entity as DTEList; if (el != null) { return(el.GetObjects()); } } break; } return(null); }
public override void DeletEntity(DTEntity e) { _entities.Remove(e); //OrderSelfMembers(); Changed(); }
public override void DeletEntity(DTEntity e) { throw new NotImplementedException("DTValue.DeletEntity"); }
public ReservedInfo(DTEntity entity, bool isComplete) { this.Entity = entity; this.IsComplete = isComplete; }
private void CollectSchemaCode(DTEntity entity, Type objectType) { if (DataUtil.IsPrimitiveType(objectType)) { _codes.Add(entity.Name, entity.GetSchemaCode(false)); return; } //以下是处理集合和对象的类型 if (objectType.IsList()) { var elementType = objectType.ResolveElementType(); var sc = entity.GetSchemaCode(false); var pos = sc.IndexOf(":"); if (pos > -1) { //对于集合类型找出成员的架构代码 var elementSC = sc.Substring(pos + 1).TrimStart("[").TrimEnd("]"); //定义了架构代码 _codes.Add(entity.Name, elementSC); //记忆一次 TryAddTypeCode(elementType, elementSC); return; } string code = null; //没有定义架构代码,先尝试从类型代码中获取 if (_typeCodes.TryGetValue(elementType, out code)) { _codes.Add(entity.Name, code); } else { _codes.Add(entity.Name, string.Empty); //定义空的架构,代表全部属性 } } else { //Object的处理 var sc = entity.GetSchemaCode(false); var pos = sc.IndexOf(":"); if (pos > -1) { sc = sc.Substring(pos + 1); //定义了架构代码 _codes.Add(entity.Name, sc); //记忆一次 TryAddTypeCode(objectType, sc); return; } string code = null; //没有定义架构代码,先尝试从类型代码中获取 if (_typeCodes.TryGetValue(objectType, out code)) { _codes.Add(entity.Name, code); } else { _codes.Add(entity.Name, string.Empty); //定义空的架构,代表全部属性 } } }
/// <summary> /// 删除成员 /// </summary> /// <param name="e"></param> public abstract void DeletEntity(DTEntity e);