From 49d210b9ad39cc0317db40bfea737855f4ec4f8d Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Thu, 29 Jan 2026 23:15:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(data):=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AD=98=E5=82=A8=E5=BA=93=E7=9A=84=E9=94=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 DataRepository 中的 GetKey 方法从私有改为受保护的虚拟方法 - 简化了基于类型的键生成逻辑,使用 FullName 替代 Name 和前缀组合 - 移除了 DataRepositoryOptions 中的 KeyPrefix 属性 - 将 UnifiedSettingsRepository 中的相关方法改为受保护的虚拟方法 - 简化了统一键生成的路径处理逻辑,移除多余的 TrimEnd 操作 - [release ci] --- .../data/DataRepositoryOptions.cs | 5 ----- GFramework.Game/data/DataRepository.cs | 12 ++++-------- GFramework.Game/data/UnifiedSettingsRepository.cs | 8 +++----- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/GFramework.Game.Abstractions/data/DataRepositoryOptions.cs b/GFramework.Game.Abstractions/data/DataRepositoryOptions.cs index 5ae6b08..8ba1944 100644 --- a/GFramework.Game.Abstractions/data/DataRepositoryOptions.cs +++ b/GFramework.Game.Abstractions/data/DataRepositoryOptions.cs @@ -23,11 +23,6 @@ public class DataRepositoryOptions /// public string BasePath { get; set; } = ""; - /// - /// 键名前缀(如 "Game",生成的键为 "Game_SettingsData") - /// - public string KeyPrefix { get; set; } = ""; - /// /// 是否在保存时自动备份 /// diff --git a/GFramework.Game/data/DataRepository.cs b/GFramework.Game/data/DataRepository.cs index e6e0181..e4a53fd 100644 --- a/GFramework.Game/data/DataRepository.cs +++ b/GFramework.Game/data/DataRepository.cs @@ -162,7 +162,7 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options = /// /// 数据类型 /// 生成的存储键 - private string GetKey() where T : IData + protected virtual string GetKey() where T : IData { return GetKey(typeof(T)); } @@ -172,13 +172,9 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options = /// /// 数据类型 /// 生成的存储键 - private string GetKey(Type type) + protected virtual string GetKey(Type type) { - var fileName = $"{_options.KeyPrefix}_{type.Name}"; - - if (string.IsNullOrEmpty(_options.BasePath)) - return fileName; - var basePath = _options.BasePath.TrimEnd('/'); - return $"{basePath}/{fileName}"; + var fileName = type.FullName!; + return string.IsNullOrEmpty(_options.BasePath) ? fileName : $"{_options.BasePath}/{fileName}"; } } \ No newline at end of file diff --git a/GFramework.Game/data/UnifiedSettingsRepository.cs b/GFramework.Game/data/UnifiedSettingsRepository.cs index fbc5d99..c3dffd4 100644 --- a/GFramework.Game/data/UnifiedSettingsRepository.cs +++ b/GFramework.Game/data/UnifiedSettingsRepository.cs @@ -219,10 +219,9 @@ public class UnifiedSettingsRepository( /// 获取统一文件的存储键名 /// /// 完整的存储键名 - private string GetUnifiedKey() + protected virtual string GetUnifiedKey() { - var name = string.IsNullOrEmpty(_options.KeyPrefix) ? fileName : $"{_options.KeyPrefix}_{fileName}"; - return string.IsNullOrEmpty(_options.BasePath) ? name : $"{_options.BasePath.TrimEnd('/')}/{name}"; + return string.IsNullOrEmpty(_options.BasePath) ? fileName : $"{_options.BasePath}/{fileName}"; } /// @@ -230,9 +229,8 @@ public class UnifiedSettingsRepository( /// /// 要获取键的类型 /// 类型的全名作为键 - private static string GetTypeKey(Type type) + protected virtual string GetTypeKey(Type type) { return type.FullName!; - // ⚠️ 刻意不用 AssemblyQualifiedName } } \ No newline at end of file