summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-18 14:44:18 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-18 14:44:18 -0400
commitf9eb16489fcf3f4c486df5f96a94edf16cf19a09 (patch)
tree8ee581968ae378682a91869e08e76ad32c064b61 /src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
parentc916cc5a1023ab81df89458ecb679405081f54c6 (diff)
downloadSMAPI-f9eb16489fcf3f4c486df5f96a94edf16cf19a09.tar.gz
SMAPI-f9eb16489fcf3f4c486df5f96a94edf16cf19a09.tar.bz2
SMAPI-f9eb16489fcf3f4c486df5f96a94edf16cf19a09.zip
refactor some methods for reuse (#468)
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs')
-rw-r--r--src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
index cc8eeb73..dcc0dac4 100644
--- a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
+++ b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
@@ -95,18 +95,14 @@ namespace StardewModdingAPI.Toolkit.Serialisation
Directory.CreateDirectory(dir);
// write file
- string json = JsonConvert.SerializeObject(model, this.JsonSettings);
+ string json = this.Serialise(model);
File.WriteAllText(fullPath, json);
}
-
- /*********
- ** Private methods
- *********/
/// <summary>Deserialize JSON text if possible.</summary>
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="json">The raw JSON text.</param>
- private TModel Deserialise<TModel>(string json)
+ public TModel Deserialise<TModel>(string json)
{
try
{
@@ -127,5 +123,13 @@ namespace StardewModdingAPI.Toolkit.Serialisation
throw;
}
}
+
+ /// <summary>Serialize a model to JSON text.</summary>
+ /// <typeparam name="TModel">The model type.</typeparam>
+ /// <param name="model">The model to serialise.</param>
+ public string Serialise<TModel>(TModel model)
+ {
+ return JsonConvert.SerializeObject(model, this.JsonSettings);
+ }
}
}