From caeb1ab80f49636ff2b33c9be079233a2c9d92d7 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:21:39 +0000 Subject: [PATCH] refactor: use ternary operator for conditional assignments This PR refactors code that used multi-line if/else statements to use the ternary operator for more concise and readable assignments. - if statement can be rewritten using the ternary operator: The original code assigned values based on Storage.ExistsAsync(key) with separate if and else blocks, leading to verbose multi-line statements. We have replaced these with single-line ternary expressions in both the generic GetAsync method and the UnifiedSettingsFile loader, reducing code duplication and improving clarity. > This Autofix was generated by AI. Please review the change before merging. --- GFramework.Game/Data/DataRepository.cs | 6 +----- GFramework.Game/Data/UnifiedSettingsDataRepository.cs | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/GFramework.Game/Data/DataRepository.cs b/GFramework.Game/Data/DataRepository.cs index 5bfff9a..5276ec0 100644 --- a/GFramework.Game/Data/DataRepository.cs +++ b/GFramework.Game/Data/DataRepository.cs @@ -46,12 +46,8 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options = { var key = location.ToStorageKey(); - T result; // 检查存储中是否存在指定键的数据 - if (await Storage.ExistsAsync(key)) - result = await Storage.ReadAsync(key); - else - result = new T(); + T result = await Storage.ExistsAsync(key) ? await Storage.ReadAsync(key) : new T(); // 如果启用事件功能,则发送数据加载完成事件 if (_options.EnableEvents) diff --git a/GFramework.Game/Data/UnifiedSettingsDataRepository.cs b/GFramework.Game/Data/UnifiedSettingsDataRepository.cs index 00a1f25..56db1cb 100644 --- a/GFramework.Game/Data/UnifiedSettingsDataRepository.cs +++ b/GFramework.Game/Data/UnifiedSettingsDataRepository.cs @@ -211,10 +211,7 @@ public class UnifiedSettingsDataRepository( var key = UnifiedKey; - if (await Storage.ExistsAsync(key)) - _file = await Storage.ReadAsync(key); - else - _file = new UnifiedSettingsFile { Version = 1 }; + _file = await Storage.ExistsAsync(key) ? await Storage.ReadAsync(key) : new UnifiedSettingsFile { Version = 1 }; _loaded = true; }