Skip to content

Commit 35ddbc4

Browse files
committed
refactor(options): 统一使用OptionAttribute替换RequiredOptionAttribute
将项目中所有使用RequiredOptionAttribute的地方统一替换为OptionAttribute并设置Required=true,保持属性使用的一致性,简化代码结构
1 parent 7f3621e commit 35ddbc4

6 files changed

Lines changed: 16 additions & 17 deletions

File tree

GameFrameX.Foundation.Tests/Options/AttributeOptionsTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private class TestOptions
2323
[HelpText("是否启用详细日志")]
2424
public bool Verbose { get; set; }
2525

26-
[RequiredOption(LongName = "api-key", Required = true)]
26+
[Option(LongName = "api-key", Required = true)]
2727
[HelpText("API密钥")]
2828
public string ApiKey { get; set; }
2929

@@ -32,8 +32,7 @@ private class TestOptions
3232

3333
private class TestOptionsWithMultipleAttributes
3434
{
35-
[Option("connection-string", EnvironmentVariable = "TEST_CONNECTION")]
36-
[RequiredOption(Required = true)]
35+
[Option("connection-string", EnvironmentVariable = "TEST_CONNECTION", Required = true)]
3736
[HelpText("数据库连接字符串")]
3837
public string ConnectionString { get; set; }
3938
}
@@ -344,4 +343,4 @@ public void Build_WithMixedEmptyAndValidEnvironmentVariables_ShouldHandleCorrect
344343
Environment.SetEnvironmentVariable("TEST_HOST", null);
345344
}
346345
}
347-
}
346+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class AdvancedFeaturesDemoConfig
4949
/// <summary>
5050
/// 应用程序名称(必需)
5151
/// </summary>
52-
[RequiredOptionAttribute("app-name")]
52+
[OptionAttribute("app-name", Required = true)]
5353
[HelpTextAttribute("应用程序的名称,用于标识应用")]
5454
public string AppName { get; set; } = string.Empty;
5555

@@ -112,7 +112,7 @@ public class AdvancedFeaturesDemoConfig
112112
/// <summary>
113113
/// 数据库连接字符串(必需)
114114
/// </summary>
115-
[RequiredOptionAttribute("database-url")]
115+
[OptionAttribute("database-url", Required = true)]
116116
[EnvironmentVariableAttribute("DATABASE_URL")]
117117
[HelpTextAttribute("数据库连接字符串,必须提供")]
118118
public string DatabaseUrl { get; set; } = string.Empty;
@@ -494,4 +494,4 @@ private static void DemonstrateAttributeCombinations()
494494
Environment.SetEnvironmentVariable("API_KEY", null);
495495
}
496496
}
497-
}
497+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class BasicDemoConfig
1818
/// <summary>
1919
/// 应用程序名称
2020
/// </summary>
21-
[RequiredOptionAttribute("app-name")]
21+
[OptionAttribute("app-name", Required = true)]
2222
public string AppName { get; set; } = string.Empty;
2323

2424
/// <summary>
@@ -269,4 +269,4 @@ private static void DemonstrateErrorHandling()
269269
}
270270
}
271271
}
272-
}
272+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ComparisonDemoConfig
1919
/// <summary>
2020
/// 应用程序名称
2121
/// </summary>
22-
[RequiredOptionAttribute("app-name")]
22+
[OptionAttribute("app-name", Required = true)]
2323
public string AppName { get; set; } = string.Empty;
2424

2525
/// <summary>
@@ -49,7 +49,7 @@ public class ComparisonDemoConfig
4949
/// <summary>
5050
/// 数据库连接字符串
5151
/// </summary>
52-
[RequiredOptionAttribute("database-url")]
52+
[OptionAttribute("database-url", Required = true)]
5353
public string DatabaseUrl { get; set; } = string.Empty;
5454
}
5555

@@ -417,4 +417,4 @@ private static void PrintConfig(string method, ComparisonDemoConfig config)
417417
Console.WriteLine($" 数据库URL: {config.DatabaseUrl}");
418418
}
419419
}
420-
}
420+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DebugModeDemoConfig
1818
/// <summary>
1919
/// 应用程序名称
2020
/// </summary>
21-
[RequiredOptionAttribute("app-name")]
21+
[OptionAttribute("app-name", Required = true)]
2222
public string AppName { get; set; } = string.Empty;
2323

2424
/// <summary>
@@ -52,7 +52,7 @@ public class DebugModeDemoConfig
5252
/// <summary>
5353
/// 数据库连接字符串
5454
/// </summary>
55-
[RequiredOptionAttribute("database-url")]
55+
[OptionAttribute("database-url", Required = true)]
5656
[EnvironmentVariableAttribute("DATABASE_URL")]
5757
public string DatabaseUrl { get; set; } = string.Empty;
5858

@@ -318,4 +318,4 @@ private static void DemonstrateDebugOutputControl()
318318
Console.WriteLine(" 5. 默认行为 (启用)");
319319
}
320320
}
321-
}
321+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class StaticMethodsDemoConfig
1818
/// <summary>
1919
/// 应用程序名称
2020
/// </summary>
21-
[RequiredOptionAttribute("app-name")]
21+
[OptionAttribute("app-name", Required = true)]
2222
public string AppName { get; set; } = string.Empty;
2323

2424
/// <summary>
@@ -294,4 +294,4 @@ private static void CompareWithTraditionalWay(string[] args)
294294
Console.WriteLine(" ✅ 类型安全 - 泛型支持,编译时类型检查");
295295
}
296296
}
297-
}
297+
}

0 commit comments

Comments
 (0)