/// <summary> /// Generates the data list. /// </summary> /// <param name="table">The table.</param> /// <param name="className">Name of the class.</param> /// <param name="headInfos">The MetadataHeadInfo list.</param> /// <returns></returns> private static List <ConfigMetadata> GenerateDataList(DataTable table, string className, List <MetadataHeadInfo> headInfos) { List <ConfigMetadata> dataList = new List <ConfigMetadata>(); int rowCount = table.Rows.Count; for (int i = DefaultDataStartRowIndex; i < rowCount; ++i) { ConfigMetadata metadata = (ConfigMetadata)ReflectionUtility.CreateClassInstance(GetMetadataFullName(className)); for (int j = 0, keysCount = headInfos.Count; j < keysCount; ++j) { string cellValue = table.Rows[i][j].ToString().Trim(); MetadataHeadInfo headInfo = headInfos[j]; // The value of primary key can not be null or empty string. if (headInfo.key == primaryKey && string.IsNullOrEmpty(cellValue)) { continue; } ITypeParser parser = GetTypeParser(headInfo.type); if (parser != null && !string.IsNullOrEmpty(cellValue)) { object value = parser.ParseValue(cellValue); ReflectionUtility.SetObjectFieldValue(metadata, headInfo.key, value); } } dataList.Add(metadata); } return(dataList); }
/// <summary> /// Creates the type parser. /// </summary> /// <param name="parserName">Name of the parser.</param> /// <returns>The instance of type parser.</returns> public static ITypeParser CreateTypeParser(Type type) { if (type != null) { ITypeParser parser = (ITypeParser)ReflectionUtility.CreateClassInstance(type); return(parser); } return(null); }
/// <summary> /// Loads the configuration files. /// </summary> /// <param name="path">The path relative to the folder Resources.</param> public void LoadConfigFiles(string path) { TextAsset[] assets = Resources.LoadAll <TextAsset>(path); foreach (TextAsset asset in assets) { Dictionary <int, Dictionary <string, string> > voStringDict = ParseConfigData(asset.text); Dictionary <int, ConfigData> voDataDict = new Dictionary <int, ConfigData>(); foreach (KeyValuePair <int, Dictionary <string, string> > kvp in voStringDict) { ConfigData configData = (ConfigData)ReflectionUtility.CreateClassInstance(asset.name); configData.ParseData(kvp.Value); voDataDict.Add(kvp.Key, configData); } configDataDict.Add(Type.GetType(asset.name), voDataDict); } }