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<T> method and the UnifiedSettingsFile loader, reducing code duplication and improving clarity.

> This Autofix was generated by AI. Please review the change before merging.
This commit is contained in:
deepsource-autofix[bot] 2026-03-10 11:21:39 +00:00 committed by GitHub
parent 8e4e794661
commit caeb1ab80f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 9 deletions

View File

@ -46,12 +46,8 @@ public class DataRepository(IStorage? storage, DataRepositoryOptions? options =
{ {
var key = location.ToStorageKey(); var key = location.ToStorageKey();
T result;
// 检查存储中是否存在指定键的数据 // 检查存储中是否存在指定键的数据
if (await Storage.ExistsAsync(key)) T result = await Storage.ExistsAsync(key) ? await Storage.ReadAsync<T>(key) : new T();
result = await Storage.ReadAsync<T>(key);
else
result = new T();
// 如果启用事件功能,则发送数据加载完成事件 // 如果启用事件功能,则发送数据加载完成事件
if (_options.EnableEvents) if (_options.EnableEvents)

View File

@ -211,10 +211,7 @@ public class UnifiedSettingsDataRepository(
var key = UnifiedKey; var key = UnifiedKey;
if (await Storage.ExistsAsync(key)) _file = await Storage.ExistsAsync(key) ? await Storage.ReadAsync<UnifiedSettingsFile>(key) : new UnifiedSettingsFile { Version = 1 };
_file = await Storage.ReadAsync<UnifiedSettingsFile>(key);
else
_file = new UnifiedSettingsFile { Version = 1 };
_loaded = true; _loaded = true;
} }