using System.Text; using Fantasy.Exporter; using Fantasy.Tools.ConfigTable; using System.Collections.Generic; namespace Exporter; public class ErrorCodeToConst : ACustomExport { private class ErrorCodeInfo { public uint Id; public string Name; public string Text; } public override void Run() { if (!Worksheets.TryGetValue("ErrorCode", out var errorCodeConfig)) { Log.Info("ErrorCode is null"); return; } var dic = new List(); for (var row = 7; row <= errorCodeConfig.Dimension.Rows; row++) { var errorCodeInfo = new ErrorCodeInfo() { Id = uint.Parse( errorCodeConfig.GetCellValue(row, 3)), Name = errorCodeConfig.GetCellValue(row, 4), Text = errorCodeConfig.GetCellValue(row, 5) }; dic.Add(errorCodeInfo); } Write(dic, CustomExportType.Server); Write(dic, CustomExportType.Client); } private void Write(List dic, CustomExportType customExportType) { var strBuilder = new StringBuilder(); strBuilder.AppendLine("namespace Fantasy\n{"); strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在ErrorCode.xsl里。"); strBuilder.AppendLine("\tpublic partial class ErrorCode\n\t{"); foreach (var errorCodeInfo in dic) { strBuilder.AppendLine($"\t\t/// \n\t\t/// {errorCodeInfo.Text}\n\t\t/// "); strBuilder.AppendLine($"\t\tpublic const uint {errorCodeInfo.Name} = {errorCodeInfo.Id};"); } strBuilder.AppendLine("\t}\n}"); Write("ErrorCode.cs", strBuilder.ToString(), customExportType); } }