From 197884e10134cc7150f2b008a7cf8556ca3b8d39 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Thu, 7 Dec 2017 20:17:29 +0100 Subject: [PATCH] defaultValues, Dispose fix --- JSON.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/JSON.cs b/JSON.cs index 8faa75c..59ace9a 100644 --- a/JSON.cs +++ b/JSON.cs @@ -127,9 +127,11 @@ namespace sharp.json } public void WriteTo(String filename,bool pretty) { - FileStream fs = new FileStream(filename, FileMode.Create); - WriteTo(fs,pretty); - fs.Close(); + using (FileStream fs = new FileStream(filename, FileMode.Create)) + { + WriteTo(fs, pretty); + fs.Close(); + } } public static JSON ReadFrom(string filename) @@ -161,6 +163,10 @@ namespace sharp.json } catch (FileNotFoundException e){ return defaultValue; } + if (source.Equals("")) + { + return defaultValue; + } return parser.Parse(source); }