提交 6dabca85 编写于 作者: J Jason Malinowski

Support serializing longs to/from the local registry

Fixes dotnet/roslyn#19629.
上级 83bc0b8d
......@@ -75,6 +75,27 @@ bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
value = subKey.GetValue(key, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
return true;
}
else if (optionKey.Option.Type == typeof(long))
{
object untypedValue = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
if (untypedValue is string stringValue)
{
// Due to a previous bug we were accidentally serializing longs as strings. Gracefully convert
// those back.
bool suceeded = long.TryParse(stringValue, out long longValue);
value = longValue;
return suceeded;
}
else if (untypedValue is long longValue)
{
value = longValue;
return true;
}
value = null;
return false;
}
else
{
// Otherwise we can just store normally
......@@ -108,6 +129,11 @@ bool IOptionPersister.TryPersist(OptionKey optionKey, object value)
subKey.SetValue(key, (bool)value ? 1 : 0, RegistryValueKind.DWord);
return true;
}
else if (optionKey.Option.Type == typeof(long))
{
subKey.SetValue(key, value, RegistryValueKind.QWord);
return true;
}
else
{
subKey.SetValue(key, value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册