private Entity(string type, VID _id, ID _root) { def = Def.Get(type); if (def == null) { throw new EntityExpection(string.Format("Entity Struct Failed, Type {0} is not exist.", type)); } entityId = _id; root = _root; Type = VType.None; ConstructEntityFromDef(); AllAttrNames = new Seq <string>(); AllListNames = new Seq <string>(); for (int i = 0; i < def.Indexes.Count; i++) { Def.Entry entry = def.GetEntry(def.Indexes[i]); if (entry.species == Def.Entry.Species.Attr) { AllAttrNames.Add(entry.name); } else { AllListNames.Add(entry.name); } } }
public void InitialList(int index, VType type, Def.Entry entry) { string name = entry.name; VarSeq newList = new VarSeq(type, entry.type); _lists[index] = newList; newList.ClearEvents(); newList.OnAdd += (rowId, value) => { if (OnListAdd != null) { OnListAdd(entityId, name, newList.keyIndexMap.GetKey(rowId)); } if (OnListRowAdd != null) { OnListRowAdd(entityId, name, rowId); } if (value is Entity) { Entity item = value as Entity; item._OnAttrChange_Private_List = delegate(ID item_entityID, string item_attrName, Var item_val) { // 关于 '=', 一个entity最多只能属于一个列表 if (OnListItemChange != null) { OnListItemChange(entityId, name, rowId, item_attrName, item_val); } if (OnListRowItemChange != null) { OnListItemChange(entityId, name, rowId, item_attrName, item_val); } }; } //_indexes[index].Add(rowId); }; newList.OnDel += (rowId, value) => { if (OnListDel != null) { OnListDel(entityId, name, newList.keyIndexMap.GetKey(rowId)); } if (OnListRowDel != null) { OnListRowDel(entityId, name, rowId); } if (value is Entity) { Entity item = value as Entity; item._OnAttrChange_Private_List = null; } }; newList.OnClear += () => { //其实并不支持Clear if (OnListClr != null) { OnListClr(entityId, name); } }; }
// ============================ Setter ============================= public bool SetList(string name, List <object> input) { int index = def.GetInd(name); if (!_lists.ContainsKey(index)) { return(false); } Def.Entry entry = def.GetEntry(index); Seq <int> originKeys = _lists[index].UsedKeys.Map(imd => (int)(VInt)_lists[index].keyIndexMap.GetKey(imd)); for (int i = 0; i < originKeys.Count; i++) { if (originKeys[i] > input.Count) { _lists[index].DelAttr(originKeys[i]); } } for (int i = 0; i < input.Count; i++) { object val = input[i]; switch (entry.type.TryConvertToEnum(VType.None)) { case VType.Bool: return(_lists[index].SetAttrBool(name, (bool)val)); case VType.Int: return(_lists[index].SetAttrInt(name, (int)val)); case VType.Long: return(_lists[index].SetAttrLong(name, (long)val)); case VType.UInt: return(_lists[index].SetAttrUInt(name, (uint)val)); case VType.ULong: return(_lists[index].SetAttrULong(name, (ulong)val)); case VType.Float: return(_lists[index].SetAttrFloat(name, (float)val)); case VType.Double: return(_lists[index].SetAttrDouble(name, (double)val)); case VType.String: return(_lists[index].SetAttrString(name, (string)val)); case VType.ID: return(_lists[index].SetAttrID(name, (ID)val)); case VType.None: default: break; } } return(true); }
public bool SetListNewRow(string listName, Var rowID) { int index = def.GetInd(listName); if (!_lists.ContainsKey(index)) { return(false); } if (_lists[index].itemType == VType.None) { Entity entity = Create(_lists[index].itemTypeName, entityId.Append(listName).Append(rowID.Format(null)), root); Def.Entry entry = def.GetEntry(index); entity.SetAttrByInd(entry.indexing, rowID); _lists[index].SetAttr(rowID, entity); } return(true); }
public bool SetListEntity(string name, Entity value) { int index = def.GetInd(name); Def.Entry entry = def.GetEntry(index); if (!_lists.ContainsKey(index)) { return(false); } if (_lists[index].itemType == VType.ID) { _lists[index].SetAttrID(value.GetAttrByInd(entry.indexing), value.entityId); } else { _lists[index].SetAttr(value.GetAttrByInd(entry.indexing), value); } return(true); }