// public object GetKeyFieldValue() // { // var keyField = EEUtility.GetRowDataKeyField(GetType()); // return keyField == null ? null : keyField.GetValue(this); // } public List <object> GetKeyFieldValues() { var keyFields = EEUtility.GetRowDataKeyFields(GetType()); List <object> res = new List <object>(keyFields.Count); for (int i = 0; i < keyFields.Count; i++) { var keyField = keyFields[i]; res.Add(keyField == null ? null : keyField.GetValue(this)); } return(res); }
private void ParseOneDataCollection(Type dataCollectionType) { try { var sheetClassName = dataCollectionType.Name; //GetSheetName(dataCollectionType); var collection = dataLoader.Load(sheetClassName); if (collection == null) { EELog.LogError("EEDataManager: Load asset error, sheet name " + sheetClassName); return; } var rowDataType = GetRowDataClassType(collection.ExcelFileName, dataCollectionType); var keyFields = EEUtility.GetRowDataKeyFields(rowDataType); if (keyFields.Count == 0) { EELog.LogError("EEDataManager: Cannot find Key field in sheet " + sheetClassName); return; } if (keyFields.Count == 1) { var keyField = keyFields[0]; var keyType = keyField.FieldType; if (keyType == typeof(int)) { var dataDict = new RowDataDictInt(); for (var i = 0; i < collection.GetDataCount(); ++i) { var data = collection.GetData(i); int key = (int)keyField.GetValue(data); dataDict.Add(key, data); } dataCollectionDictInt.Add(rowDataType, dataDict); } else if (keyType == typeof(string)) { var dataDict = new RowDataDictStr(); for (var i = 0; i < collection.GetDataCount(); ++i) { var data = collection.GetData(i); string key = (string)keyField.GetValue(data); dataDict.Add(key, data); } dataCollectionDictStr.Add(rowDataType, dataDict); } else { EELog.LogError(string.Format("Load {0} failed. There is no valid Key field in ", dataCollectionType.Name)); } } else if (keyFields.Count == 2) { var dataDict = new RowDataTowKeyDict(); for (var i = 0; i < collection.GetDataCount(); ++i) { var data = collection.GetData(i); var key1 = keyFields[0].GetValue(data); var key2 = keyFields[1].GetValue(data); dataDict.Add(new Keys <object, object>(key1, key2), data); } dataCollectionDictTowKeys.Add(rowDataType, dataDict); } else if (keyFields.Count == 3) { var dataDict = new RowDataThreeKeyDict(); for (var i = 0; i < collection.GetDataCount(); ++i) { var data = collection.GetData(i); var key1 = keyFields[0].GetValue(data); var key2 = keyFields[1].GetValue(data); var key3 = keyFields[2].GetValue(data); dataDict.Add(new Keys <object, object, object>(key1, key2, key3), data); } dataCollectionDictThreeKeys.Add(rowDataType, dataDict); } else if (keyFields.Count > 3) { Debug.LogErrorFormat("EasyExcel 导入功能暂不支持 key超过3个的表!"); } } catch (Exception e) { EELog.LogError(e.ToString()); } }