public void Add(Player player) { var region = RegionRepository.FromPosition(player.Position); _playerEntityList.Add(player); player.World = this; region.AddEntity(player); }
/// <summary>从数据读写器加载数据。无数据时返回空集合而不是null。</summary> /// <param name="dr">数据读写器</param> /// <returns>实体数组</returns> public IEntityList LoadData(IDataReader dr) { //if (dr == null) return null; //// 先移到第一行,要取字段名等信息 //if (!dr.Read()) return null; // 准备好实体列表 IEntityList list = TypeX.CreateInstance(typeof(EntityList <>).MakeGenericType(EntityType)) as IEntityList; if (dr == null) { return(list); } // 先移到第一行,要取字段名等信息 if (!dr.Read()) { return(list); } List <FieldItem> ps = new List <FieldItem>(); List <String> exts = new List <String>(); for (int i = 0; i < dr.FieldCount; i++) { String name = dr.GetName(i); FieldItem fi = null; if (FieldItems.TryGetValue(name, out fi)) { ps.Add(fi); } else { exts.Add(name); } } // 遍历每一行数据,填充成为实体 do { // 由实体操作者创建实体对象,因为实体操作者可能更换 IEntity entity = Factory.Create(); foreach (FieldItem item in ps) { SetValue(entity, item.Name, item.Type, dr[item]); } foreach (String item in exts) { SetValue(entity, item, null, dr[item]); } list.Add(entity); } while (dr.Read()); return(list); }
public object ReadRowSet(IRowReader reader) { IEntityList list = CreateObjectList(); while (reader.Read()) { list.Add(ReadRow(reader)); } return(list); }
/// <summary>加载数据表。无数据时返回空集合而不是null。</summary> /// <param name="dt">数据表</param> /// <returns>实体数组</returns> public IEntityList LoadData(DataTable dt) { //if (dt == null || dt.Rows.Count < 1) return null; // 准备好实体列表 //EntityList<TEntity> list = new EntityList<TEntity>(dt.Rows.Count); IEntityList list = TypeX.CreateInstance(typeof(EntityList <>).MakeGenericType(EntityType), dt.Rows.Count) as IEntityList; if (dt == null || dt.Rows.Count < 1) { return(list); } List <FieldItem> ps = new List <FieldItem>(); List <String> exts = new List <String>(); foreach (DataColumn item in dt.Columns) { String name = item.ColumnName; FieldItem fi = null; if (FieldItems.TryGetValue(name, out fi)) { ps.Add(fi); } else { exts.Add(name); } } // 遍历每一行数据,填充成为实体 foreach (DataRow dr in dt.Rows) { //TEntity obj = new TEntity(); // 由实体操作者创建实体对象,因为实体操作者可能更换 IEntity obj = Factory.Create(); LoadData(dr, obj, ps, exts); list.Add(obj); } return(list); }
public IEntityList FindMany(IFinder finder, int Page, int PageSize) { #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif IEntityList result = CreateObjectList(); PagedDataSet ds = GetPagedDataSet(finder, Page, PageSize); result.PagingInfo = ds.PagingInfo; foreach (DataRow row in ds.Tables[0].Rows) { result.Add(ReadRow(new RowReader(row))); } #if DEBUG sw.Stop(); LogMessage("FindMany+1", finder.FindCommand, sw.ElapsedMilliseconds); #endif return(result); }
public void Add(Entity entity) { using (entitieSemaphore.Wait()) entities.Add(entity); }