Skip to content

Commit 81da61f

Browse files
committed
refactor(Options): 移除HelpTextAttribute及相关使用
移除不再使用的HelpTextAttribute类,并清理所有相关测试和示例代码中对HelpTextAttribute的引用。这些帮助文本信息将由其他方式提供,简化了选项属性的配置结构。
1 parent 53071bd commit 81da61f

5 files changed

Lines changed: 5 additions & 52 deletions

File tree

GameFrameX.Foundation.Options/Attributes/HelpTextAttribute.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

GameFrameX.Foundation.Options/OptionsDebugger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public static void PrintParsedOptions<T>(T options) where T : class
3939

4040
// 计算最大显示宽度
4141
int maxWidth = 0;
42-
var optionInfos = new List<(PropertyInfo property, string displayName, Attributes.OptionAttribute optionAttribute, Attributes.HelpTextAttribute helpTextAttribute)>();
42+
var optionInfos = new List<(PropertyInfo property, string displayName, Attributes.OptionAttribute optionAttribute)>();
4343

4444
foreach (var property in properties.OrderBy(p => p.Name))
4545
{
4646
var attributes = property.GetCustomAttributes(true);
4747
var optionAttribute = attributes.OfType<Attributes.OptionAttribute>().FirstOrDefault();
48-
var helpTextAttribute = attributes.OfType<Attributes.HelpTextAttribute>().FirstOrDefault();
48+
4949

5050
string displayName;
5151
if (optionAttribute != null)
@@ -59,7 +59,7 @@ public static void PrintParsedOptions<T>(T options) where T : class
5959
}
6060

6161
maxWidth = Math.Max(maxWidth, displayName.Length);
62-
optionInfos.Add((property, displayName, optionAttribute, helpTextAttribute));
62+
optionInfos.Add((property, displayName, optionAttribute));
6363
}
6464

6565
// 添加2个字符的缓冲空间
@@ -75,15 +75,15 @@ public static void PrintParsedOptions<T>(T options) where T : class
7575
int defaultWidth = DefaultValueHeader.Length;
7676
int helpWidth = HelpTextHeader.Length;
7777

78-
foreach (var (property, displayName, optionAttribute, helpTextAttribute) in optionInfos)
78+
foreach (var (property, displayName, optionAttribute) in optionInfos)
7979
{
8080
var value = property.GetValue(options);
8181
var displayValue = FormatPropertyValue(value) ?? string.Empty;
8282
var typeName = GetFriendlyTypeName(property.PropertyType) ?? string.Empty;
8383
var required = optionAttribute != null ? (optionAttribute.Required ? RequiredYesLabel : RequiredNoLabel) : string.Empty;
8484
var description = optionAttribute != null ? (optionAttribute.Description ?? NoDescriptionLabel) : NoOptionAttributeLabel;
8585
var defaultVal = optionAttribute?.DefaultValue?.ToString() ?? string.Empty;
86-
var helpText = helpTextAttribute?.HelpText ?? string.Empty;
86+
var helpText = string.Empty;
8787

8888
nameWidth = Math.Max(nameWidth, displayName.Length);
8989
valueWidth = Math.Max(valueWidth, displayValue.Length);

GameFrameX.Foundation.Tests/Options/AttributeOptionsTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ public class AttributeOptionsTests
1212
private class TestOptions
1313
{
1414
[Option("port", DefaultValue = 8080, EnvironmentVariable = "TEST_PORT")]
15-
[HelpText("应用程序监听的端口")]
1615
public int Port { get; set; }
1716

1817
[Option(LongName = "host", EnvironmentVariable = "TEST_HOST", DefaultValue = "localhost")]
19-
[HelpText("应用程序主机名")]
2018
public string Host { get; set; }
2119

2220
[FlagOption(LongName = "verbose")]
23-
[HelpText("是否启用详细日志")]
2421
public bool Verbose { get; set; }
2522

2623
[Option(LongName = "api-key", Required = true)]
27-
[HelpText("API密钥")]
2824
public string ApiKey { get; set; }
2925

3026
public string NoAttributeProperty { get; set; } = "默认值";
@@ -33,7 +29,6 @@ private class TestOptions
3329
private class TestOptionsWithMultipleAttributes
3430
{
3531
[Option("connection-string", EnvironmentVariable = "TEST_CONNECTION", Required = true)]
36-
[HelpText("数据库连接字符串")]
3732
public string ConnectionString { get; set; }
3833
}
3934

GameFrameX.Foundation.Tests/Options/Demos/AdvancedFeaturesDemo.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,103 +50,90 @@ public class AdvancedFeaturesDemoConfig
5050
/// 应用程序名称(必需)
5151
/// </summary>
5252
[OptionAttribute("app-name", Required = true)]
53-
[HelpTextAttribute("应用程序的名称,用于标识应用")]
5453
public string AppName { get; set; } = string.Empty;
5554

5655
/// <summary>
5756
/// 服务器主机地址
5857
/// </summary>
5958
[OptionAttribute("host", DefaultValue = "localhost")]
6059
[EnvironmentVariableAttribute("SERVER_HOST")]
61-
[HelpTextAttribute("服务器主机地址,支持IP地址或域名")]
6260
public string Host { get; set; } = "localhost";
6361

6462
/// <summary>
6563
/// 服务器端口号
6664
/// </summary>
6765
[OptionAttribute("port", DefaultValue = 8080)]
6866
[EnvironmentVariableAttribute("SERVER_PORT")]
69-
[HelpTextAttribute("服务器监听端口号,范围1-65535")]
7067
public int Port { get; set; } = 8080;
7168

7269
/// <summary>
7370
/// 是否启用SSL
7471
/// </summary>
7572
[FlagOptionAttribute("ssl")]
7673
[EnvironmentVariableAttribute("ENABLE_SSL")]
77-
[HelpTextAttribute("启用SSL/TLS加密连接")]
7874
public bool EnableSsl { get; set; } = false;
7975

8076
/// <summary>
8177
/// 日志级别(枚举类型)
8278
/// </summary>
8379
[OptionAttribute("log-level", DefaultValue = LogLevel.Info)]
8480
[EnvironmentVariableAttribute("LOG_LEVEL")]
85-
[HelpTextAttribute("日志记录级别:Debug, Info, Warning, Error, Fatal")]
8681
public LogLevel LogLevel { get; set; } = LogLevel.Info;
8782

8883
/// <summary>
8984
/// 超时时间(浮点数类型)
9085
/// </summary>
9186
[OptionAttribute("timeout", DefaultValue = 30.5)]
9287
[EnvironmentVariableAttribute("REQUEST_TIMEOUT")]
93-
[HelpTextAttribute("请求超时时间,单位为秒,支持小数")]
9488
public double Timeout { get; set; } = 30.5;
9589

9690
/// <summary>
9791
/// 启动时间(日期时间类型)
9892
/// </summary>
9993
[OptionAttribute("start-time")]
10094
[EnvironmentVariableAttribute("START_TIME")]
101-
[HelpTextAttribute("应用启动时间,格式:yyyy-MM-dd HH:mm:ss")]
10295
public DateTime? StartTime { get; set; }
10396

10497
/// <summary>
10598
/// 应用程序GUID
10699
/// </summary>
107100
[OptionAttribute("app-id")]
108101
[EnvironmentVariableAttribute("APP_ID")]
109-
[HelpTextAttribute("应用程序唯一标识符(GUID格式)")]
110102
public Guid? AppId { get; set; }
111103

112104
/// <summary>
113105
/// 数据库连接字符串(必需)
114106
/// </summary>
115107
[OptionAttribute("database-url", Required = true)]
116108
[EnvironmentVariableAttribute("DATABASE_URL")]
117-
[HelpTextAttribute("数据库连接字符串,必须提供")]
118109
public string DatabaseUrl { get; set; } = string.Empty;
119110

120111
/// <summary>
121112
/// API密钥(可选)
122113
/// </summary>
123114
[OptionAttribute("api-key")]
124115
[EnvironmentVariableAttribute("API_KEY")]
125-
[HelpTextAttribute("第三方API访问密钥,可选")]
126116
public string? ApiKey { get; set; }
127117

128118
/// <summary>
129119
/// 最大连接数(可空整数)
130120
/// </summary>
131121
[OptionAttribute("max-connections", DefaultValue = 100)]
132122
[EnvironmentVariableAttribute("MAX_CONNECTIONS")]
133-
[HelpTextAttribute("最大并发连接数,默认100")]
134123
public int? MaxConnections { get; set; } = 100;
135124

136125
/// <summary>
137126
/// 缓存大小(十进制数)
138127
/// </summary>
139128
[OptionAttribute("cache-size", DefaultValue = 256.5)]
140129
[EnvironmentVariableAttribute("CACHE_SIZE")]
141-
[HelpTextAttribute("缓存大小,单位MB,支持小数")]
142130
public decimal CacheSize { get; set; } = 256.5m;
143131

144132
/// <summary>
145133
/// 是否启用调试模式(可空布尔值)
146134
/// </summary>
147135
[FlagOptionAttribute("debug")]
148136
[EnvironmentVariableAttribute("DEBUG")]
149-
[HelpTextAttribute("启用调试模式,显示详细日志")]
150137
public bool? Debug { get; set; }
151138
}
152139

GameFrameX.Foundation.Tests/Options/Demos/BasicUsageDemo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class BasicDemoConfig
5656
/// </summary>
5757
[OptionAttribute("database-url", Description = "xxxxxxxxxxxxxxxxxdsakfjhjhjakfhj 温热欻穿oquikocxkzuisaanmsaioajkdjsa开双冲akjhjkfjaok返矿卡健康返矿桑吉很但恐韩克很检控方炯看就肯斯的就看妇科琅丹福斯翻看东街口翻开三即可"
5858
)]
59-
[HelpText("数据库连接字符串, 例如: \"Server=localhost;Port=3306;Database=test;Uid=root;Pwd=123456;\"")]
6059
[EnvironmentVariableAttribute("DATABASE_URL")]
6160
public string? DatabaseUrl { get; set; }
6261
}

0 commit comments

Comments
 (0)