Skip to content

Commit 5b205c2

Browse files
committed
update JsonFileCacheManager
1 parent 3a6ffc6 commit 5b205c2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

MojangAPI/Cache/JsonFileCacheManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace MojangAPI.Cache
55
{
6-
public class JsonFileCacheManager<T> : ICacheManager<T>
6+
public class JsonFileCacheManager<T> : ICacheManager<T> where T : new()
77
{
88
public string CacheFilePath { get; private set; }
99

@@ -12,7 +12,7 @@ public JsonFileCacheManager(string filepath)
1212
this.CacheFilePath = filepath;
1313
}
1414

15-
public virtual T GetDefaultObject() => default(T);
15+
public virtual T GetDefaultObject() => new T();
1616

1717
public T ReadCache()
1818
{
@@ -22,7 +22,7 @@ public T ReadCache()
2222
try
2323
{
2424
string filecontent = File.ReadAllText(CacheFilePath);
25-
return JsonSerializer.Deserialize<T>(filecontent);
25+
return JsonSerializer.Deserialize<T>(filecontent) ?? new T();
2626
}
2727
catch
2828
{

0 commit comments

Comments
 (0)