提交 52076203 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #19732 from CyrusNajmabadi/optionresilience

Be resilient to options being serialized as strings.
......@@ -77,24 +77,41 @@ bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
}
else if (optionKey.Option.Type == typeof(long))
{
object untypedValue = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
if (untypedValue is string stringValue)
var untypedValue = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
switch (untypedValue)
{
// 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;
case 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;
}
case long longValue:
value = longValue;
return true;
}
else if (untypedValue is long longValue)
}
else if (optionKey.Option.Type == typeof(int))
{
var untypedValue = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
switch (untypedValue)
{
value = longValue;
return true;
}
case string stringValue:
{
// Due to a previous bug we were accidentally serializing ints as strings.
// Gracefully convert those back.
var suceeded = int.TryParse(stringValue, out int intValue);
value = intValue;
return suceeded;
}
value = null;
return false;
case int intValue:
value = intValue;
return true;
}
}
else
{
......@@ -104,6 +121,9 @@ bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
}
}
}
value = null;
return false;
}
bool IOptionPersister.TryPersist(OptionKey optionKey, object value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册