Skip to content

Commit f6dac0b

Browse files
ilovepatatosMrBlue
authored andcommitted
Fix DataFileSystem.ReadObject not handling empty files
1 parent 3e9bf9b commit f6dac0b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/DataFileSystem.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ public string[] GetFiles(string path = "", string searchPattern = "*")
9898

9999
public T ReadObject<T>(string name)
100100
{
101-
if (!ExistsDatafile(name))
101+
T instance = default;
102+
103+
if (ExistsDatafile(name))
104+
instance = GetFile(name).ReadObject<T>();
105+
106+
if (instance == null)
102107
{
103-
T instance = Activator.CreateInstance<T>();
108+
instance = Activator.CreateInstance<T>();
104109
WriteObject(name, instance);
105-
return instance;
106110
}
107111

108-
return GetFile(name).ReadObject<T>();
112+
return instance;
109113
}
110114

111115
public void WriteObject<T>(string name, T Object, bool sync = false) => GetFile(name).WriteObject(Object, sync);

0 commit comments

Comments
 (0)