提交 2afbb069 编写于 作者: C CyrusNajmabadi

Be reselient to options being serialized as strings.

上级 ecb10874
......@@ -75,6 +75,48 @@ 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))
{
var 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.
var 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 if (optionKey.Option.Type == typeof(int))
{
var 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.
var suceeded = int.TryParse(stringValue, out int intValue);
value = intValue;
return suceeded;
}
else if (untypedValue is int intValue)
{
value = intValue;
return true;
}
value = null;
return false;
}
else
{
// Otherwise we can just store normally
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册