static string GetFieldDesc(List <STransEntry> transEntryList, string propName) { //string desc = "\t\tstring desc = \"(\" + tid + \")\" + \"" + "v_" + transEntryList[0].name; string desc = "\t\tstring desc = string.Format(\"({0})v_" + transEntryList[0].name; int nList = 0; for (int i = 1; i < transEntryList.Count; ++i) { STransEntry entry = transEntryList[i]; desc += HobaText.Format(".{0}", entry.name); if (entry.isList) { //desc += HobaString.Format("[\" + i{1} + \"]", nList); ++nList; desc += "[{" + nList + "}]";; } } desc = HobaText.Format("{0}.{1}", desc, propName); desc += "\","; //format end desc += " tid"; for (int i = 0; i < nList; ++i) { desc += HobaText.Format(", i{0}", i); } //desc += "\";"; desc += ");"; return(desc); }
static string Get_GenerateTranslateValues_Template_CS(string template_Name, TemplateFieldTranslator.CStringFieldInfo info, bool ignoreTranslateTxt) { string strText = string.Format(@" public static void GenerateTranlateValues_{0}()", template_Name); strText += @" {"; strText += string.Format(@" _ListTranslateValue.Clear(); "); //得到如 [[[ExecutionUnit][Event]][AddFightSpeciality]] List <STranslateField> transFields = new List <STranslateField>(); GetFieldInfo(transFields, template_Name, info, ignoreTranslateTxt); //strText += string.Format("//{0}\n", template_Name); //strText += string.Format("//Template.{0}Module.Manager\n", template_Name); strText += string.Format(@" //{0} foreach (var kv in Template.{1}Module.Manager.Instance.GetTemplateMap())", template_Name, template_Name); strText += @" {"; strText += string.Format(@" int tid = kv.Key; var v_{0} = kv.Value; ", template_Name); //读取每个字段 foreach (var transfield in transFields) { //字段简称 string field = string.Format("{0}.{1}", transfield.parentMemberName, transfield.propName); strText += "\n"; List <STransEntry> transEntryList = ParseParentMemberNameList(transfield); //生成 string parentListName = null; string strMember = "v_" + transEntryList[0].name; int nListBraces = 0; for (int i = 1; i < transEntryList.Count; ++i) { STransEntry entry = transEntryList[i]; if (!entry.isList) { strMember += string.Format(".{0}", entry.name); if (parentListName != null) { if (i + 1 == transEntryList.Count) { //get string desc //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "." + transfield.propName + "\";"; strText += GetFieldDesc(transEntryList, transfield.propName); strText += string.Format(@" string v = {0}.{1}.{2};", parentListName, entry.name, transfield.propName); strText += "\nstring field = \"" + field + "\";\n"; //添加 strText += @" if (!string.IsNullOrEmpty(v)) _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});"; } else { parentListName = string.Format("{0}.{1}", parentListName, entry.name); } } } else { strMember += string.Format(".{0}", entry.name); if (parentListName != null) { parentListName = string.Format("{0}.{1}", parentListName, entry.name); } string strList = (parentListName != null ? parentListName : strMember); string strVar = string.Format("v_{0}", entry.name); strText += string.Format(@" for(int i{0} = 0; i{1} < {2}.Count; ++i{3})", nListBraces, nListBraces, strList, nListBraces); //try strText += @" {try { "; strText += string.Format(@" var {0} = {1}[i{2}]; ", strVar, strList, nListBraces); if (i + 1 == transEntryList.Count) { //get string desc //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "[\" + i + \"]" + "." + transfield.propName + "\";"; strText += GetFieldDesc(transEntryList, transfield.propName); strText += string.Format(@" string v = {0}.{1};", strVar, transfield.propName); strText += "\nstring field = \"" + field + "\";\n"; //添加 strText += @" if (!string.IsNullOrEmpty(v)) _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});"; } ++nListBraces; parentListName = strVar; } } if (nListBraces == 0) //没有List字段 { //try strText += @" {try { "; //get string desc //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "." + transfield.propName + "\";"; strText += GetFieldDesc(transEntryList, transfield.propName); strText += string.Format(@" string v = {0}.{1};", strMember, transfield.propName); strText += "\nstring field = \"" + field + "\";\n"; //添加 strText += @" if (!string.IsNullOrEmpty(v)) _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});"; //catch strText += @" } catch(NullReferenceException) {}}"; } else { for (int i = 0; i < nListBraces; ++i) { //catch strText += @" } catch(NullReferenceException) {}}"; } } } strText += @" } "; strText += @" } "; return(strText); }