56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
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<ErrorCodeInfo>();
|
|
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<ErrorCodeInfo> 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/// <summary>\n\t\t/// {errorCodeInfo.Text}\n\t\t/// </summary>");
|
|
strBuilder.AppendLine($"\t\tpublic const uint {errorCodeInfo.Name} = {errorCodeInfo.Id};");
|
|
}
|
|
|
|
strBuilder.AppendLine("\t}\n}");
|
|
Write("ErrorCode.cs", strBuilder.ToString(), customExportType);
|
|
}
|
|
} |