Esempio n. 1
0
        /// <summary>
        /// 使用反射产生对应表的List数据
        /// </summary>
        /// <param name="configTableDataTypeDefine"></param>
        /// <param name="tableInfo"></param>
        /// <returns></returns>
        private System.Object FillDynamicListWithTableData(Type configTableDataTypeDefine, ConfigDataTableInfo tableInfo)
        {
            var listType  = typeof(List <>).MakeGenericType(configTableDataTypeDefine);
            var list      = Activator.CreateInstance(listType);
            var addMethod = listType.GetMethod("Add");

            if (tableInfo.Row > 2)
            {
                for (int i = 2; i < tableInfo.Row; i++)
                {
                    var data = Activator.CreateInstance(configTableDataTypeDefine);
                    foreach (var columnInfo in tableInfo.ColumnInfoList)
                    {
                        try
                        {
                            var filedInfo = configTableDataTypeDefine.GetField("m_" + columnInfo.ColumnName, BindingFlags.NonPublic | BindingFlags.Instance);
                            var value     = ConfigDataColumnTypeSolver.GetValue(tableInfo.ReadCell(i, columnInfo.ColumnNo), columnInfo.TypeStr);
                            filedInfo.SetValue(data, value);
                        }catch (Exception e)
                        {
                            Debug.LogError(string.Format("FillDynamicListWithTableData while process table {0} column {1}, msg:{2}", tableInfo.TableName, columnInfo.ColumnName, e.Message));
                        }
                    }
                    addMethod.Invoke((object)list, new object[] { data });
                }
            }
            return(list);
        }
Esempio n. 2
0
 /// <summary>
 /// 提取枚举表信息
 /// </summary>
 private void ParseEnumTableInfo()
 {
     m_enumTupleDic.Clear();
     if (m_rawDataReader.Row > 2)
     {
         for (int i = 2; i < m_rawDataReader.Row; i++)
         {
             string enumName = m_rawDataReader.ReadCell(i, 0);
             int    value    = ConfigDataColumnTypeSolver.ParseInt(m_rawDataReader.ReadCell(i, 1));
             if (m_enumTupleDic.ContainsKey(enumName))
             {
                 ThrowException("enum table has contained the same key:" + enumName);
             }
             m_enumTupleDic.Add(enumName, value);
         }
     }
 }
Esempio n. 3
0
        /*
         * /// <summary>
         * /// 获取外键的实际数据类型
         * /// </summary>
         * /// <param name="tableName"></param>
         * /// <param name="columnName"></param>
         * /// <param name="typeStr"></param>
         * /// <returns></returns>
         * private Type GetForeignKeyType(string tableName, string columnName, string typeStr)
         * {
         *  Type resultType = null;
         *  string[] tuple = typeStr.Split(new char[] { '.' });
         *  if (tuple.Length != 2)
         *  {
         *      throw new Exception(string.Format("the column {0} at table {1} is a foreign key, but typeStr is not a tuple", columnName, tableName));
         *  }
         *  string foreignTableName = tuple[0];
         *  string foreignColumnName = tuple[1];
         *  if (!m_configDataTableInfoDic.ContainsKey(foreignTableName))
         *  {
         *      throw new Exception(string.Format("can't find the foreign table {0} for the column {1} at table {2} ", foreignTableName, columnName, tableName));
         *  }
         *  var foreignTabelInfo = m_configDataTableInfoDic[foreignTableName];
         *  ConfigDataTableColumnInfo foreignColumnInfo = null;
         *  foreach (var columnInfo in foreignTabelInfo.ColumnInfoList)
         *  {
         *      if (columnInfo.ColumnName == name)
         *      {
         *          foreignColumnInfo = columnInfo;
         *          break;
         *      }
         *  }
         *  if (foreignColumnInfo == null || foreignColumnInfo.m_columnTypeParseState != ConfigDataTableColumnTypeParseState.Determine)
         *  {
         *      throw new Exception(string.Format("can't find the foreign column {0} for the column {1} at table {2}", foreignColumnName, columnName, tableName));
         *  }
         *  resultType = foreignColumnInfo.ColumnType;
         *  return resultType;
         * }
         */

        /*
         * private Type GetColumnType(string tableName, string columnName, string typeStr)
         * {
         *  if (typeStr.StartsWith("List<") && typeStr.EndsWith(">"))
         *  {
         *      //List数据类型
         *      var unDetermineGenericType = typeof(List<>);
         *      List<Type> typeParams = new List<Type>();
         *      int index1 = typeStr.IndexOf("List<");
         *      int index2 = typeStr.LastIndexOf(">");
         *      string subStr = typeStr.Substring(index1 + "List<".Length + 1, index2);
         *      string[] typeParamStrs = subStr.Split(new char[] { ',' });
         *      for (int i = 0; i < typeParamStrs.Length; i++)
         *      {
         *          typeParams.Add(GetColumnType(tableName, columnName, typeParamStrs[i]));
         *      }
         *      return unDetermineGenericType.MakeGenericType(typeParams.ToArray());
         *  }
         *  else if (typeStr.IndexOf(".") != -1)
         *  {
         *      //外键类型
         *      return GetForeignKeyType(tableName, columnName, typeStr);
         *  }
         *  else
         *  {
         *      //基础类型
         *      return TypeSolver.GetType(typeStr);
         *  }
         * }
         */

        /// <summary>
        /// 解析列类型
        /// </summary>
        /// <returns></returns>
        private IEnumerator SolveColumnDataType()
        {
            //第一次遍历,解析基本数据类型
            foreach (var tableInfo in m_configDataTableInfoDic.Values)
            {
                foreach (var columnInfo in tableInfo.ColumnInfoList)
                {
                    var columnType = ConfigDataColumnTypeSolver.GetType(columnInfo.TypeStr);
                    columnInfo.m_columnTypeParseState = ConfigDataTableColumnTypeParseState.UnDetermine;
                    if (columnType != null)
                    {
                        columnInfo.SetColumnType(columnType);
                        columnInfo.m_columnTypeParseState = ConfigDataTableColumnTypeParseState.Determine;
                    }
                    yield return(null);
                }
            }

            /*
             * //第二次遍历, 解析外键类型
             * foreach (var tableInfo in m_configDataTableInfoDic.Values)
             * {
             *  foreach (var columnInfo in tableInfo.ColumnInfoList)
             *  {
             *      if(columnInfo.m_columnTypeParseState != ConfigDataTableColumnTypeParseState.UnDetermine)
             *      {
             *          continue;
             *      }
             *      string typeStr = columnInfo.TypeStr;
             *      Type columnType = GetColumnType(columnInfo.TableName, columnInfo.ColumnName, typeStr);
             *      columnInfo.m_columnTypeParseState = ConfigDataTableColumnTypeParseState.Fail;
             *      if (columnType != null)
             *      {
             *          columnInfo.SetColumnType(columnType);
             *          columnInfo.m_columnTypeParseState = ConfigDataTableColumnTypeParseState.Determine;
             *      }
             *
             *  }
             * }
             */
        }