diff --git a/Source/FileManager/PersistentDictionary.cs b/Source/FileManager/PersistentDictionary.cs index 22d58e4a..c74a9c35 100644 --- a/Source/FileManager/PersistentDictionary.cs +++ b/Source/FileManager/PersistentDictionary.cs @@ -38,10 +38,11 @@ namespace FileManager if (!stringCache.ContainsKey(propertyName)) { var jObject = readFile(); - if (!jObject.ContainsKey(propertyName)) - return defaultValue; - stringCache[propertyName] = jObject[propertyName].Value(); - } + if (jObject.ContainsKey(propertyName)) + stringCache[propertyName] = jObject[propertyName].Value(); + 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(); 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(), out var enumVal)