This commit is contained in:
龙腾猫跃 committed 2026-07-18 00:01:14 +08:00
1 parent 7d7dac3762
commit d8697c7ddb
1 file changed
+7 -2
+7 -2
View File
@@ -18,12 +18,17 @@ public static class RegistryUtils {
return (result is string str && str == NULL_STRING ? null : result, true); return (result is string str && str == NULL_STRING ? null : result, true);
} }
/// <summary> /// <summary>
/// 读取注册表键,若该键不存在则返回 <paramref name="defaultValue"/>。 /// 读取注册表键,若该键不存在或发生异常则返回 <paramref name="defaultValue"/>。
/// <para/>若键值为 <see cref="NULL_STRING"/>,则返回 <c>null</c>。 /// <para/>若键值为 <see cref="NULL_STRING"/>,则返回 <c>null</c>。
/// </summary> /// </summary>
public static object? ReadOrDefault(string keyPath, object? defaultValue) { public static object? TryRead(string keyPath, object? defaultValue = null) {
try {
var (result, exists) = Read(keyPath); var (result, exists) = Read(keyPath);
return exists ? result : defaultValue; return exists ? result : defaultValue;
} catch (Exception ex) {
Logger.Warn(ex, $"读取注册表键失败({keyPath})");
return defaultValue;
}
} }
/// <summary> /// <summary>