public ConfigRow[] getRows(System.Enum key1, int value1, System.Enum key2, int value2) { List <ConfigRow> listRow = new List <ConfigRow>(); int count = reader.getRowCount(); int col1 = -1; int col2 = -1; for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } if (col1 == -1) { col1 = row.getIndex(key1); } if (col2 == -1) { col2 = row.getIndex(key2); } if (col1 >= 0 && col2 >= 0 && row.equalsValue(key1, value1) && row.equalsValue(key2, value2)) { listRow.Add(row); } } return(listRow.ToArray()); }
static public Dictionary <TKey, TData> ParseTable <TKey, TData>(ConfigTable table) where TKey : new() where TData : new() { Dictionary <TKey, TData> dataDictionary = new Dictionary <TKey, TData>(); System.Reflection.FieldInfo[] keyFieldList = getDataFields <TKey>(); System.Reflection.FieldInfo[] dataFieldList = getDataFields <TData>(); IEnumerator <ConfigRow> rowIterator = table.getRowEnumerator(); while (rowIterator.MoveNext()) { ConfigRow configRow = rowIterator.Current; if (configRow == null) { continue; } TKey key = parseData <TKey>(keyFieldList, table, configRow); TData data = parseData <TData>(dataFieldList, table, configRow); dataDictionary.Add(key, data); } return(dataDictionary); }
public ConfigRow getRow(System.Enum key1, int value1, System.Enum key2, int value2) { int count = reader.getRowCount(); int col1 = -1; int col2 = -1; for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } if (col1 == -1) { col1 = row.getIndex(key1); } if (col2 == -1) { col2 = row.getIndex(key2); } if (col1 >= 0 && col2 >= 0 && row.equalsValue(col1, value1) && row.equalsValue(col2, value2)) { return(row); } } return(null); }
public ConfigRow[] getRows(ConfigRow[] srcList, System.Enum key, int value) { if (srcList == null) { return(null); } List <ConfigRow> listRow = new List <ConfigRow>(); int col = -1; int count = reader.getRowCount(); for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } if (col == -1) { col = row.getIndex(key); } if (col >= 0 && row.equalsValue(col, value)) { listRow.Add(row); } } return(listRow.ToArray()); }
//根据条件值返回行 public ConfigRow getRow(System.Enum key, int value) { int count = reader.getRowCount(); int col = -1; for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } if (col == -1) { col = row.getIndex(key); } if (col >= 0 && row.equalsValue(col, value)) { return(row); } } return(null); }
protected virtual bool openStream(StreamReader sr) { if (sr == null) { return(false); } int line = 0; try { for (; !sr.EndOfStream; line++) { string strLine = sr.ReadLine(); if (strLine == null) { break; } string[] cols = strLine.Split(','); if (line == 0) { _colAmount = cols.Length; for (int i = 0; i < _colAmount; i++) { _columnNameList.Add(cols[i]); } continue; } ConfigRow newRow = new ConfigRow(_colAmount); for (int col = 0; col < _colAmount; col++) { newRow.addValue(cols[col]); } _dataList.Add(newRow); } } catch (System.Exception ex) { UnityEngine.Debug.Log(ex.Message + " in line " + line + "\n" + ex.StackTrace); return(false); } finally { if (sr != null) { sr.Close(); } } return(true); }
public ConfigRow getRow(System.Enum key1, int value1, System.Enum key2, int value2, System.Enum key3, int value3) { int count = reader.getRowCount(); for (int index = 0; index < count; index++) { ConfigRow row = getRow(index); if (row == null) { continue; } if (row.equalsValue(key1, value1) && row.equalsValue(key2, value2) && row.equalsValue(key3, value3)) { return(row); } } return(null); }
public ConfigRow[] getRows(System.Enum key1, int value1, System.Enum key2, int value2, System.Enum key3, int value3) { List <ConfigRow> listRow = new List <ConfigRow>(); int count = reader.getRowCount(); for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } if (row.equalsValue(key1, value1) && row.equalsValue(key2, value2) && row.equalsValue(key3, value3)) { listRow.Add(row); } } return(listRow.ToArray()); }
//public ConfigRow[] rows //{ // get { return this._rowList.ToArray(); } //} //public List<ConfigRow> RowList //{ // get { return this._rowList; } //} //根据条件值返回行 public ConfigRow getRow(System.Enum key, string value) { int count = reader.getRowCount(); for (int index = 0; index < count; index++) { ConfigRow row = reader.getRow(index); if (row == null) { continue; } string temp = ""; if (row.getStringValue(key, out temp)) { if (temp == value) { return(row); } } } return(null); }
static public List <TData> ParseTable <TData>(ConfigTable table) where TData : new() { List <TData> dataList = new List <TData>(); System.Reflection.FieldInfo[] dataFieldList = getDataFields <TData>(); IEnumerator <ConfigRow> rowIterator = table.getRowEnumerator(); while (rowIterator.MoveNext()) { ConfigRow configRow = rowIterator.Current; if (configRow == null) { continue; } TData data = parseData <TData>(dataFieldList, table, configRow); dataList.Add(data); } return(dataList); }
static private TData parseData <TData>(System.Reflection.FieldInfo[] fieldInfoList, ConfigTable table, ConfigRow configRow) where TData : new() { TData data = new TData(); foreach (System.Reflection.FieldInfo fieldInfo in fieldInfoList) { string configValue = getConfigValue(fieldInfo, table, configRow); if (!string.IsNullOrEmpty(configValue)) { try { System.ComponentModel.TypeConverter typeConverter = getTypeConverter(fieldInfo); object fieldValue = typeConverter.ConvertFromString(configValue); fieldInfo.SetValue(data, fieldValue); } catch (Exception) { act.debug.PrintSystem.LogError("[CONFIG] error in field : " + fieldInfo.Name); throw; } } } return(data); }
static private string getConfigValue(System.Reflection.FieldInfo fieldInfo, ConfigTable table, ConfigRow configRow) { string[] columnNames = getDescriptionNames(fieldInfo); if (columnNames != null) { string configValue = string.Empty; int columnNamesLength = columnNames.Length; for (int i = 0; i < columnNamesLength; i++) { if (i > 0) { configValue += SEPARATOR; } string columnName = columnNames[i]; int columnIndex = 0; string cellValue = ""; ListAttribute[] attributes = (ListAttribute[])fieldInfo.GetCustomAttributes(typeof(ListAttribute), false); if (attributes.Length > 0) { //如果是多欄位要合成list 就執行這邊 string columnNameTemp = columnName + 0; columnIndex = table.getColumnIndex(columnNameTemp); if (columnIndex != -1) { cellValue = configRow.getStringValue(columnIndex); if (!string.IsNullOrEmpty(cellValue)) { configValue = cellValue; } } for (int j = 1; j < 100; j++) { columnNameTemp = columnName + j; columnIndex = table.getColumnIndex(columnNameTemp); if (columnIndex != -1) { cellValue = configRow.getStringValue(columnIndex); if (!string.IsNullOrEmpty(cellValue)) { configValue = configValue + ":" + cellValue; } } } } else { columnIndex = table.getColumnIndex(columnName); cellValue = configRow.getStringValue(columnIndex); configValue += cellValue; } } return(configValue); } return(null); }