Cache default values
This commit is contained in:
parent
2b243a6934
commit
50a8c7508a
1 changed files with 11 additions and 6 deletions
|
|
@ -38,10 +38,11 @@ namespace FileManager
|
|||
if (!stringCache.ContainsKey(propertyName))
|
||||
{
|
||||
var jObject = readFile();
|
||||
if (!jObject.ContainsKey(propertyName))
|
||||
return defaultValue;
|
||||
stringCache[propertyName] = jObject[propertyName].Value<string>();
|
||||
}
|
||||
if (jObject.ContainsKey(propertyName))
|
||||
stringCache[propertyName] = jObject[propertyName].Value<string>();
|
||||
else
|
||||
stringCache[propertyName] = defaultValue;
|
||||
}
|
||||
|
||||
return stringCache[propertyName];
|
||||
}
|
||||
|
|
@ -50,12 +51,16 @@ namespace FileManager
|
|||
{
|
||||
var obj = GetObject(propertyName);
|
||||
|
||||
if (obj is null) return defaultValue;
|
||||
if (obj is null)
|
||||
{
|
||||
objectCache[propertyName] = defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
if (obj.GetType().IsAssignableTo(typeof(T))) return (T)obj;
|
||||
if (obj is JObject jObject) return jObject.ToObject<T>();
|
||||
if (obj is JValue jValue)
|
||||
{
|
||||
if (jValue.Type == JTokenType.String && typeof(T).IsAssignableTo(typeof(Enum)))
|
||||
if (typeof(T).IsAssignableTo(typeof(Enum)))
|
||||
{
|
||||
return
|
||||
Enum.TryParse(typeof(T), jValue.Value<string>(), out var enumVal)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue