提交示例代码

This commit is contained in:
Bob.Song
2026-03-05 11:39:06 +08:00
commit 25958f58c3
2534 changed files with 209593 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
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);
}
}