private static void ProductClass_Message(List <Array> listArr, List <string> listStr, string IclassName, string gate) { var classNameArr = listArr[0]; var className = classNameArr.GetValue(classNameArr.Length - 1); string gateClassName = ""; string result = ""; string gateFile = ""; if (gate.Contains('.')) { var gateArr = gate.Split('.'); //className = /*IclassName + gateArr[1] + "_" + */className; gateClassName = IclassName + gateArr[1]; gateFile = "D:/TestClass/" + gateClassName + ".cs"; if (!File.Exists(gateFile)) { MyClass gateClass = new MyClass(gateClassName); gateClass.AddNameSpace("System"); result = gateClass.ToString(); } else { result = File.ReadAllText(gateFile).ToString(); gateFile = "D:/TestClass/" + gateClassName + ".cs"; } } else { //className = IclassName + className; gateClassName = gate; gateFile = "D:/TestClass/" + IclassName + gateClassName + ".cs"; } MyClass c = new MyClass(className.ToString()); var subClassName = ""; for (int i = 1; i < listArr.Count; i++) { var arr = listArr[i]; subClassName = arr.GetValue(0).ToString(); MyClass subClass = new MyClass(subClassName); for (int n = 1; n < arr.Length; n++) { var f = new MyField(); //if(n == 1) //{ // field = string.Format("public {0};", arr.GetValue(n)); //} //else //{ // field = string.Format("public {0};", arr.GetValue(n)); //} string field = string.Format("public {0};", arr.GetValue(n)); f.SetContent(field); subClass.AddField(f); } c.AddClass(subClass); } //添加field if (listStr.Count > 1) { for (int i = 0; i < listStr.Count; i++) { //先判断类型 var f = new MyField(); string field = ""; var arrField = listStr[i].Split(' '); if (arrField[0] == subClassName) { var str = listStr[i].Insert(listStr[i].LastIndexOf(' '), "[]"); field = string.Format("public {0};", str); } else { field = string.Format("public {0};", listStr[i]); } //if (i == 0) //{ // field = string.Format("public {0};", listStr[i]); //} //else //{ // field = string.Format("public {0};", listStr[i]); //} f.SetContent(field); c.AddField(f); } } var code = c.ToString(); if (gate.Contains('.')) { result = result.Insert(result.LastIndexOf('}'), code); } else { result = code; } var files = path + "/RouteClass/Response_" + c.Name + ".cs"; if (File.Exists(files)) { File.Delete(files); } File.WriteAllText(gateFile, result); //AssetDatabase.Refresh(); //ProductMethodClass_All(c, gate, listStr, IclassName); ProductMethodClass_Now(className.ToString(), gate, listStr, IclassName); }
//创建类_Client private static void ProductClass_NoMessage(List <string> strList, string IclassName, string gate) { var className = ""; var gateClassName = ""; var result = ""; string gateFile = ""; if (gate.Contains('.')) { var gateArr = gate.Split('.'); className = /*IclassName + gateArr[1] + "_" + */ strList[0]; gateClassName = IclassName + gateArr[1]; gateFile = "D:/TestClass/" + gateClassName + ".cs"; if (!File.Exists(gateFile)) { MyClass gateClass = new MyClass(gateClassName); gateClass.AddNameSpace("System"); result = gateClass.ToString(); } else { result = File.ReadAllText(gateFile).ToString(); } } else { className = IclassName + strList[0]; gateClassName = gate; gateFile = "D:/TestClass/" + IclassName + gateClassName + ".cs"; } //if(strList.Count) //c.AddNameSpace("System"); //添加field if (strList.Count > 1) { MyClass c = new MyClass(className); for (int i = 1; i < strList.Count; i++) { //先判断类型 var f = new MyField(); string field; if (i == 1) { field = string.Format("public {0};", strList[i]); } else { field = string.Format("public {0};", strList[i]); } f.SetContent(field); c.AddField(f); } var code = c.ToString(); if (gate.Contains('.')) { result = result.Insert(result.LastIndexOf('}'), code); } else { //Debug.Log(className); result = code; } } //result = result.Insert(result.LastIndexOf('}'),code); var dir = Path.GetDirectoryName(path + "/RouteClass/"); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } var files = path + "/RouteClass/" + className + ".cs"; if (File.Exists(files)) { File.Delete(files); } //ProductMethodClass(c, gate, strList,IclassName); ProductMethodClass_Now(className, gate, strList, IclassName); File.WriteAllText(gateFile, result); }