/// <summary> /// 创建数据表 /// </summary> /// <param name="dataRowType">数据行的类型</param> /// <param name="text">要解析的数据表文本</param> /// <param name="nameInType">数据表类型下的名称</param> /// <returns>要创建的数据表</returns> public IDataTable CreateDataTable(Type dataRowType, string text, string nameInType = "") { if (dataRowType == null) { Debug.LogError("数据行类型为空"); return(null); } if (!typeof(IDataRow).IsAssignableFrom(dataRowType)) { Debug.LogError("数据行类型不合法"); return(null); } if (HasDataTable(dataRowType, nameInType)) { Debug.LogError("数据表已存在"); return(null); } Type dataTableType = typeof(DataTable <>).MakeGenericType(dataRowType); IDataTable dataTable = (IDataTable)Activator.CreateInstance(dataTableType, nameInType); //分割数据表文本 string[] dataRowTexts = m_DataTableHelper.SplitToDataRows(text); //按行依次添加到数据表对象里 foreach (string dataRowText in dataRowTexts) { dataTable.AddDataRow(dataRowText); } m_DataTables.Add(Utility.Text.GetFullName(dataRowType, nameInType), dataTable); return(dataTable); }