Update `IJsonHelper` to use `IHtmlContent`

- part of #3123 (2 of 5 or so)
- do not expose specific `HtmlString` class
This commit is contained in:
Doug Bunting 2015-11-23 16:44:33 -08:00
parent d84587a99d
commit 7bb0a1a4fe
2 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Html.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
@ -14,15 +15,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Returns serialized JSON for the <paramref name="value"/>. /// Returns serialized JSON for the <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">The value to serialize as JSON.</param> /// <param name="value">The value to serialize as JSON.</param>
/// <returns>A new <see cref="HtmlString"/> containing the serialized JSON.</returns> /// <returns>A new <see cref="IHtmlContent"/> containing the serialized JSON.</returns>
HtmlString Serialize(object value); IHtmlContent Serialize(object value);
/// <summary> /// <summary>
/// Returns serialized JSON for the <paramref name="value"/>. /// Returns serialized JSON for the <paramref name="value"/>.
/// </summary> /// </summary>
/// <param name="value">The value to serialize as JSON.</param> /// <param name="value">The value to serialize as JSON.</param>
/// <param name="serializerSettings">The <see cref="JsonSerializerSettings"/> to be used by the serializer.</param> /// <param name="serializerSettings">
/// <returns>A new <see cref="HtmlString"/> containing the serialized JSON.</returns> /// The <see cref="JsonSerializerSettings"/> to be used by the serializer.
HtmlString Serialize(object value, JsonSerializerSettings serializerSettings); /// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the serialized JSON.</returns>
IHtmlContent Serialize(object value, JsonSerializerSettings serializerSettings);
} }
} }

View File

@ -4,9 +4,10 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using Newtonsoft.Json; using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc.ViewFeatures namespace Microsoft.AspNet.Mvc.ViewFeatures
{ {
@ -32,13 +33,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
} }
/// <inheritdoc /> /// <inheritdoc />
public HtmlString Serialize(object value) public IHtmlContent Serialize(object value)
{ {
return SerializeInternal(_jsonOutputFormatter, value); return SerializeInternal(_jsonOutputFormatter, value);
} }
/// <inheritdoc /> /// <inheritdoc />
public HtmlString Serialize(object value, JsonSerializerSettings serializerSettings) public IHtmlContent Serialize(object value, JsonSerializerSettings serializerSettings)
{ {
if (serializerSettings == null) if (serializerSettings == null)
{ {
@ -50,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return SerializeInternal(jsonOutputFormatter, value); return SerializeInternal(jsonOutputFormatter, value);
} }
private HtmlString SerializeInternal(JsonOutputFormatter jsonOutputFormatter, object value) private IHtmlContent SerializeInternal(JsonOutputFormatter jsonOutputFormatter, object value)
{ {
var stringWriter = new StringWriter(CultureInfo.InvariantCulture); var stringWriter = new StringWriter(CultureInfo.InvariantCulture);
jsonOutputFormatter.WriteObject(stringWriter, value); jsonOutputFormatter.WriteObject(stringWriter, value);