(client) feat:实现定义数据的ToString输出

This commit is contained in:
m0_75251201
2025-07-12 17:06:15 +08:00
parent 16fef53625
commit 1b9bfbab33
2 changed files with 84 additions and 4 deletions

View File

@ -1,13 +1,14 @@
using System.Text;
using System.Xml.Linq;
namespace Data
{
public class Define
public abstract class Define
{
public string defName;
public string label;
public string discription;
public string description;
public string packID;
/// <summary>
/// 初始化方法,根据传入的 XML 元素 (<paramref name="xmlDef"/>) 进行处理。
@ -34,9 +35,24 @@ namespace Data
{
defName = xmlDef.Element("defName")?.Value;
label = xmlDef.Element("label")?.Value;
discription = xmlDef.Element("discription")?.Value;
description = xmlDef.Element("description")?.Value;
return false;
}
public override string ToString()
{
// 定义对齐格式(左对齐,固定宽度)
const int labelWidth = -15; // 标签左对齐占15字符
const int valueWidth = -30; // 值左对齐占30字符
var sb = new StringBuilder();
sb.AppendLine($"{"DefName:",labelWidth}{defName,valueWidth}");
sb.AppendLine($"{"Label:",labelWidth}{label,valueWidth}");
sb.AppendLine($"{"Description:",labelWidth}{description,valueWidth}");
sb.AppendLine($"{"PackID:",labelWidth}{packID,valueWidth}");
return sb.ToString();
}
}
}