Skip to content

Commit d413099

Browse files
committed
[增加]1. 增加全局参数重复设置的异常判断和参数检查
1 parent ec50794 commit d413099

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

GameFrameX.Utility/Setting/GlobalSettings.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GameFrameX.Foundation.Json;
2+
using GameFrameX.Utility.Extensions;
23

34
namespace GameFrameX.Utility.Setting;
45

@@ -71,15 +72,27 @@ public static void Load(string path)
7172
/// <remarks>
7273
/// 此方法用于更新全局的当前设置。
7374
/// 通常在应用程序启动时或需要切换配置时调用。
75+
/// 该方法具有以下特点:
76+
/// 1. 只能设置一次,重复设置会抛出异常
77+
/// 2. 不允许传入null值
78+
/// 3. 会自动校正SaveDataInterval的值,如果小于5000毫秒则使用默认值
7479
/// </remarks>
80+
/// <exception cref="InvalidOperationException">当CurrentSetting已存在时抛出此异常</exception>
81+
/// <exception cref="ArgumentNullException">当传入的setting参数为null时抛出此异常</exception>
7582
public static void SetCurrentSetting(AppSetting setting)
7683
{
84+
if (CurrentSetting.IsNotNull())
85+
{
86+
throw new InvalidOperationException("当前设置已经存在,不能再次设置");
87+
}
88+
7789
ArgumentNullException.ThrowIfNull(setting, nameof(setting));
78-
CurrentSetting = setting;
79-
if (setting.SaveDataInterval < 1000)
90+
if (setting.SaveDataInterval < 5000)
8091
{
8192
setting.SaveDataInterval = GlobalConst.SaveIntervalInMilliSeconds;
8293
}
94+
95+
CurrentSetting = setting;
8396
}
8497

8598
/// <summary>

0 commit comments

Comments
 (0)