summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-07 22:41:37 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-07 22:41:37 -0400
commita500812e88ac5a8acdd9732963e6fae95c0a73e6 (patch)
tree9f36571698b14ab4d898385d7bb14998efd30836 /src/SMAPI.Web/Framework
parentc58d01d0cf45d6f5c7f75281cb6270afc68272db (diff)
downloadSMAPI-a500812e88ac5a8acdd9732963e6fae95c0a73e6.tar.gz
SMAPI-a500812e88ac5a8acdd9732963e6fae95c0a73e6.tar.bz2
SMAPI-a500812e88ac5a8acdd9732963e6fae95c0a73e6.zip
update web project to .NET Core 3.1
Diffstat (limited to 'src/SMAPI.Web/Framework')
-rw-r--r--src/SMAPI.Web/Framework/Extensions.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/SMAPI.Web/Framework/Extensions.cs b/src/SMAPI.Web/Framework/Extensions.cs
index e0da1424..96463233 100644
--- a/src/SMAPI.Web/Framework/Extensions.cs
+++ b/src/SMAPI.Web/Framework/Extensions.cs
@@ -1,8 +1,12 @@
using System;
using JetBrains.Annotations;
+using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Razor;
+using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Routing;
+using Newtonsoft.Json;
namespace StardewModdingAPI.Web.Framework
{
@@ -34,5 +38,16 @@ namespace StardewModdingAPI.Web.Framework
}
return url;
}
+
+ /// <summary>Get a serialized JSON representation of the value.</summary>
+ /// <param name="page">The page to extend.</param>
+ /// <param name="value">The value to serialize.</param>
+ /// <returns>The serialized JSON.</returns>
+ /// <remarks>This bypasses unnecessary validation (e.g. not allowing null values) in <see cref="IJsonHelper.Serialize"/>.</remarks>
+ public static IHtmlContent ForJson(this RazorPageBase page, object value)
+ {
+ string json = JsonConvert.SerializeObject(value);
+ return new HtmlString(json);
+ }
}
}