/// <summary> /// C# 将解析到的xml生成string,并赋值到sb /// 这个类 是 唯一的 特殊性太强 直接写 /// </summary> void sWriteCSFileContent(StringBuilder sb, AllBaseCmdFileData fileData) { List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); for (int i = 0; i < fileData.mAllBaseCmdList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mAllBaseCmdList[i], fileData.mClassName, true); //将ParamData转为string declareStringList.AddRange(outString.mOutDeclareString.ToArray()); //赋值 声明string packStringList.AddRange(outString.mOutPackString.ToArray()); //赋值 写入string unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); //赋值 读取string } sb.AppendLine("public class " + fileData.mClassName + " : " + fileData.mFatherName); sb.AppendLine("{"); //声明 for (int j = 0; j < declareStringList.Count; ++j) { sb.AppendLine("\t" + declareStringList[j]); } sb.AppendLine(); //写声明消息值 sb.AppendLine("\tpublic const byte " + fileData.mGsCmd + " = " + fileData.mNum + ";"); sb.AppendLine(""); sb.AppendLine("\tpublic " + fileData.mClassName + "()"); sb.AppendLine("\t{"); sb.AppendLine("\t\tgsCmd = " + fileData.mGsCmd + ";"); sb.AppendLine("\t}"); sb.AppendLine(""); //写打包 sb.AppendLine("\tpublic override void Pack()"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.Pack();"); for (int k = 0; k < packStringList.Count; ++k) { sb.AppendLine("\t\t" + packStringList[k]); } sb.AppendLine("\t}"); sb.AppendLine(""); //写解包 sb.AppendLine("\tpublic override void UnPack(byte[] msg)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.UnPack(msg);"); for (int m = 0; m < unpackStringList.Count; ++m) { sb.AppendLine("\t\t" + unpackStringList[m]); } sb.AppendLine("\t}"); sb.AppendLine("}"); }
/// <summary> /// C# 将解析到的xml生成string,并赋值到sb /// </summary> void sWriteCSFileContent(StringBuilder sb, DataStructFileData fileData) { List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); for (int i = 0; i < fileData.mParamList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mParamList[i], fileData.mClassName); //将ParamData转为string declareStringList.AddRange(outString.mOutDeclareString.ToArray()); //赋值 声明string packStringList.AddRange(outString.mOutPackString.ToArray()); //赋值 写入string unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); //赋值 读取string } if (fileData.mFather == "NULL" || fileData.mFather == null) { sb.AppendLine("public class " + fileData.mClassName); } else { sb.AppendLine("public class " + fileData.mClassName + " : " + fileData.mFather); } sb.AppendLine("{"); //声明变量 for (int j = 0; j < declareStringList.Count; ++j) { sb.AppendLine("\t" + declareStringList[j]); } sb.AppendLine(); //PackData 写数据 if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\tpublic override void PackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.PackData(byteBuffer);"); } else { sb.AppendLine("\tpublic virtual void PackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); } for (int k = 0; k < packStringList.Count; ++k) { sb.AppendLine("\t\t" + packStringList[k]); } sb.AppendLine("\t}"); sb.AppendLine(); //UnPackData 读数据 if (fileData.mFather != "NULL" & fileData.mFather != null) { sb.AppendLine("\tpublic override void UnPackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); sb.AppendLine("\t\tbase.UnPackData(byteBuffer);"); } else { sb.AppendLine("\tpublic virtual void UnPackData(ByteBuffer byteBuffer)"); sb.AppendLine("\t{"); } for (int m = 0; m < unpackStringList.Count; ++m) { sb.AppendLine("\t\t" + unpackStringList[m]); } sb.AppendLine("\t}"); sb.AppendLine("}"); sb.AppendLine(); }
void sWriteCSFileContent(string fileType, CmdStructFileData fileData) { StringBuilder sb = new StringBuilder(); NetCmdXmlParser.sWriteFileHeadComment(sb, fileData.mClassName, fileData.mDescribe); //生成注释的文件头 NetCmdXmlParser.sWriteFileHeadNameSpace(sb); //生成命名空间 //所需XML数据 List <string> declareStringList = new List <string>(); List <string> packStringList = new List <string>(); List <string> unpackStringList = new List <string>(); List <string> ctorStringList = new List <string>(); //初始化字符串 for (int i = 0; i < fileData.mCmdList.Count; ++i) { ParamDataOutString outString = CmdParserComUitls.CmdParamParserDeclare_CS(fileData.mCmdList[i], fileData.mClassName, true); declareStringList.AddRange(outString.mOutDeclareString.ToArray()); packStringList.AddRange(outString.mOutPackString.ToArray()); unpackStringList.AddRange(outString.mOutUnpackString.ToArray()); ctorStringList.AddRange(outString.mOutCtorString.ToArray()); } string filePathName = ""; if (fileData.mPathName != null) { filePathName = fileData.mPathName + "/"; } string outFilePath = ""; //生成文件位置 bool _isWrite = false; switch (fileType) { case "C#_C": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_C + filePathName + fileData.mClassName + "_C.cs"; sWriteCSFileContent_C(sb, fileData, declareStringList, packStringList); _isWrite = true; break; case "C#_S": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_S + filePathName + fileData.mClassName + "_S.cs"; sWriteCSFileContent_S(sb, fileData, declareStringList, unpackStringList, ctorStringList); _isWrite = true; break; case "C#_Handler": outFilePath = NetCmdXmlParser.targetFileBasePath + cmdOutFilePath_Handler + filePathName + fileData.mClassName + "_Handler.cs"; if (!File.Exists(outFilePath)) { sWriteCSFileContent_Handler(sb, fileData); _isWrite = true; } else { return; } break; } if (_isWrite) { NetCmdXmlParser.sWriteStringToFile(outFilePath, sb); } }