/// <summary> /// 填充config的数据,主要填充以下字段 /// FieldList,KeyType,KeyFieldName /// /// </summary> /// <param name="fieldInfos"></param> /// <param name="gValueDic"></param> /// <param name="valueDic"></param> /// <param name="configName"></param> /// <returns></returns> private bool FillConfig(CfgFieldInfo[] fieldInfos, Dictionary <string, string> gValueDic, Dictionary <string, string> valueDic, string configName) { List <CfgFieldInfo> keyFields = new List <CfgFieldInfo>(fieldInfos.Length); for (int i = 0; i < fieldInfos.Length; i++) { CfgFieldInfo info = fieldInfos[i]; if (info.FunType == FunType.Key) { keyFields.Add(info); } //处理注释中的换行 if (!string.IsNullOrEmpty(info.Desc) && (info.Desc.Contains("\r") || info.Desc.Contains("\n"))) { info.Desc = info.Desc.Replace("\r\n", "${newLine}"); info.Desc = info.Desc.Replace("\n\r", "${newLine}"); info.Desc = info.Desc.Replace("\n", "${newLine}"); info.Desc = info.Desc.Replace("\r", "${newLine}"); info.Desc = info.Desc.Replace("${newLine}", "\r\n /// "); } } //没有指定主键,默认第一个 if (keyFields.Count == 0) { keyFields.Add(fieldInfos[0]); } //创建CfgDao文件 if (fieldInfos.Length < 1) { UnityEngine.Debug.LogError("xml没有字段信息" + "CfgCodeCreator.Do"); return(false); } if (keyFields.Count == 1) { //只有一个key的情况 CfgFieldInfo keyField = keyFields[0]; valueDic["KeyType"] = keyField.Type; valueDic["KeyFieldName"] = keyField.Name; } else { valueDic["KeyType"] = "string"; string keyCode = ""; for (int i = 0; i < keyFields.Count; i++) { CfgFieldInfo keyField = keyFields[i]; if (i == 0) { keyCode += keyField.Name + ".ToString()"; } else { keyCode += " + \"_\" + " + keyField.Name + ".ToString()"; } } valueDic["KeyFieldName"] = keyCode; } //处理字段声名 valueDic["FieldList"] = TemplateEngine.DoList(" public ${Type} ${Name};\r\n\r\n", fieldInfos, new[] { "Type", "Name" }, (s, info) => { if (!string.IsNullOrEmpty(info.Desc)) { string desc = " /// <summary>\r\n /// " + info.Desc + "\r\n /// </summary>\r\n"; s = desc + s; } return(s); }); return(true); }