summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-30 18:55:16 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-30 18:55:16 -0400
commit482a91962ac02cf83c2647fd7e5ba8627bd0bb0b (patch)
treedeb6d10f11185beba973d07e9510f790588071dc /src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs
parent22806ab900721a61b142937bc58dd33727d377f9 (diff)
parentd4f172fef160d277d5161d96a26d5174e6fc14ca (diff)
downloadSMAPI-482a91962ac02cf83c2647fd7e5ba8627bd0bb0b.tar.gz
SMAPI-482a91962ac02cf83c2647fd7e5ba8627bd0bb0b.tar.bz2
SMAPI-482a91962ac02cf83c2647fd7e5ba8627bd0bb0b.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs')
-rw-r--r--src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs
index bd15c7bb..64d8738e 100644
--- a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs
+++ b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs
@@ -31,9 +31,14 @@ namespace StardewModdingAPI.Framework.Serialisation
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="fullPath">The absolete file path.</param>
/// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
+ /// <exception cref="InvalidOperationException">The given path is empty or invalid.</exception>
public TModel ReadJsonFile<TModel>(string fullPath)
where TModel : class
{
+ // validate
+ if (string.IsNullOrWhiteSpace(fullPath))
+ throw new ArgumentException("The file path is empty or invalid.", nameof(fullPath));
+
// read file
string json;
try
@@ -53,11 +58,18 @@ namespace StardewModdingAPI.Framework.Serialisation
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="fullPath">The absolete file path.</param>
/// <param name="model">The model to save.</param>
+ /// <exception cref="InvalidOperationException">The given path is empty or invalid.</exception>
public void WriteJsonFile<TModel>(string fullPath, TModel model)
where TModel : class
{
+ // validate
+ if (string.IsNullOrWhiteSpace(fullPath))
+ throw new ArgumentException("The file path is empty or invalid.", nameof(fullPath));
+
// create directory if needed
string dir = Path.GetDirectoryName(fullPath);
+ if (dir == null)
+ throw new ArgumentException("The file path is invalid.", nameof(fullPath));
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);