示例#1
0
        /// <summary>
        /// 创建数据表。
        /// </summary>
        /// <param name="dataRowType">数据表行的类型。</param>
        /// <param name="name">数据表名称。</param>
        /// <param name="text">要解析的数据表文本。</param>
        /// <returns>要创建的数据表。</returns>
        public DataTableBase CreateDataTable(Type dataRowType, string name, string text)
        {
            if (dataRowType == null)
            {
                throw new AshException("Data row type is invalid.");
            }

            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))
            {
                throw new AshException(string.Format("Data row type '{0}' is invalid.", dataRowType.FullName));
            }

            if (HasDataTable(dataRowType, name))
            {
                throw new AshException(string.Format("Already exist data table '{0}'.", Utility.Text.GetFullName(dataRowType, name)));
            }

            Type          dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType);
            DataTableBase dataTable     = (DataTableBase)Activator.CreateInstance(dataTableType, name);

            string[] dataRowTexts = m_DataTableHelper.SplitToDataRows(text);
            foreach (string dataRowText in dataRowTexts)
            {
                dataTable.AddDataRow(dataRowText);
            }

            m_DataTables.Add(Utility.Text.GetFullName(dataRowType, name), dataTable);
            return(dataTable);
        }
示例#2
0
        private DataTableBase InternelGetDataTable(string fullName)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(fullName, out dataTable))
            {
                return(dataTable);
            }

            return(null);
        }
示例#3
0
        private bool InternalDestroyDataTable(string fullName)
        {
            DataTableBase dataTable = null;

            if (m_DataTables.TryGetValue(fullName, out dataTable))
            {
                dataTable.Shutdown();
                return(m_DataTables.Remove(fullName));
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// 获取所有数据表。
        /// </summary>
        /// <returns>所有数据表。</returns>
        public DataTableBase[] GetAllDataTables()
        {
            int index = 0;

            DataTableBase[] dataTables = new DataTableBase[m_DataTables.Count];
            foreach (KeyValuePair <string, DataTableBase> dataTable in m_DataTables)
            {
                dataTables[index++] = dataTable.Value;
            }

            return(dataTables);
        }