public void Init(string userId) { //反射DB数据表类型 Assembly assembly = Assembly.Load(m_AssemblyName); Type[] types = assembly.GetExportedTypes(); Func <Attribute[], bool> isAttr = o => { foreach (Attribute a in o) { if (a is DatabaseRowAttribute) { return(true); } } return(false); }; Type[] DBRowTypes = types.Where(o => { return(isAttr(Attribute.GetCustomAttributes(o, true))); }).ToArray(); for (int i = 0; i < DBRowTypes.Length; i++) { string dbTableName = DBRowTypes[i].Name; Type dbRowType = DBRowTypes[i]; DBTableBase dbTable; if (m_DataTables.ContainsKey(dbTableName)) { dbTable = m_DataTables[dbTableName]; } else { dbTable = CreateDBTable(dbRowType, dbTableName); } if (dbTable == null) { throw new GameFrameworkException("Can create dbTable:" + dbTableName); } //读取当前用户的数据库数据,并添加到DB表 string[] items = { "Id", "UserId" }; string[] cols = { "UserId" }; string[] operation = { "=" }; string[] values = { userId }; var dr = GameEntry.Database.SelectWhere(dbTableName, items, cols, operation, values); while (dr.Read()) { //Log.Warning("CreateDB:" + dr.GetString(dr.GetOrdinal("Id"))); int drId = int.Parse(dr.GetString(dr.GetOrdinal("Id"))); string drUserId = dr.GetString(dr.GetOrdinal("UserId")); IDBRow dbRow = (IDBRow)Activator.CreateInstance(DBRowTypes[i], drId, drUserId); dbRow.Load(); dbTable.AddDBRow(drId, dbRow); } } }