Temporarily rename 'Json' to 'JsonUtil' to avoid name clash

This commit is contained in:
Steve Sanderson 2018-02-26 12:06:28 +00:00
parent 1b0b5c61fe
commit 1c5acfbdcc
5 changed files with 16 additions and 11 deletions

View File

@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Blazor.Browser.Services.Temporary @using Microsoft.AspNetCore.Blazor
@using Microsoft.AspNetCore.Blazor.Browser.Services.Temporary
@inject HttpClient Http @inject HttpClient Http
<h1>Weather forecast</h1> <h1>Weather forecast</h1>
@ -40,7 +41,7 @@ else
protected override async Task OnInitAsync() protected override async Task OnInitAsync()
{ {
var json = await Http.GetStringAsync("/sample-data/weather.json"); var json = await Http.GetStringAsync("/sample-data/weather.json");
forecasts = Microsoft.AspNetCore.Blazor.Json.Deserialize<WeatherForecast[]>(json); forecasts = JsonUtil.Deserialize<WeatherForecast[]>(json);
} }
class WeatherForecast class WeatherForecast

View File

@ -23,10 +23,10 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Interop
{ {
// This is a low-perf convenience method that bypasses the need to deal with // This is a low-perf convenience method that bypasses the need to deal with
// .NET memory and data structures on the JS side // .NET memory and data structures on the JS side
var argsJson = args.Select(Json.Serialize); var argsJson = args.Select(JsonUtil.Serialize);
var resultJson = InvokeUnmarshalled<string>("invokeWithJsonMarshalling", var resultJson = InvokeUnmarshalled<string>("invokeWithJsonMarshalling",
argsJson.Prepend(identifier).ToArray()); argsJson.Prepend(identifier).ToArray());
return Json.Deserialize<TRes>(resultJson); return JsonUtil.Deserialize<TRes>(resultJson);
} }
/// <summary> /// <summary>

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Rendering
// This can be simplified in the future when the Mono WASM runtime is enhanced. // This can be simplified in the future when the Mono WASM runtime is enhanced.
public static void DispatchEvent(string eventDescriptorJson, string eventArgsJson) public static void DispatchEvent(string eventDescriptorJson, string eventArgsJson)
{ {
var eventDescriptor = Json.Deserialize<BrowserEventDescriptor>(eventDescriptorJson); var eventDescriptor = JsonUtil.Deserialize<BrowserEventDescriptor>(eventDescriptorJson);
var eventArgs = ParseEventArgsJson(eventDescriptor.EventArgsType, eventArgsJson); var eventArgs = ParseEventArgsJson(eventDescriptor.EventArgsType, eventArgsJson);
var browserRenderer = BrowserRendererRegistry.Find(eventDescriptor.BrowserRendererId); var browserRenderer = BrowserRendererRegistry.Find(eventDescriptor.BrowserRendererId);
browserRenderer.DispatchBrowserEvent( browserRenderer.DispatchBrowserEvent(
@ -33,11 +33,11 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Rendering
switch (eventArgsType) switch (eventArgsType)
{ {
case "mouse": case "mouse":
return Json.Deserialize<UIMouseEventArgs>(eventArgsJson); return JsonUtil.Deserialize<UIMouseEventArgs>(eventArgsJson);
case "keyboard": case "keyboard":
return Json.Deserialize<UIKeyboardEventArgs>(eventArgsJson); return JsonUtil.Deserialize<UIKeyboardEventArgs>(eventArgsJson);
case "change": case "change":
return Json.Deserialize<UIChangeEventArgs>(eventArgsJson); return JsonUtil.Deserialize<UIChangeEventArgs>(eventArgsJson);
default: default:
throw new ArgumentException($"Unsupported value '{eventArgsType}'.", nameof(eventArgsType)); throw new ArgumentException($"Unsupported value '{eventArgsType}'.", nameof(eventArgsType));
} }

View File

@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Services.Temporary
} }
private string SerializeHeadersAsJson(HttpRequestMessage request) private string SerializeHeadersAsJson(HttpRequestMessage request)
=> Json.Serialize( => JsonUtil.Serialize(
(from header in request.Headers.Concat(request.Content?.Headers ?? Enumerable.Empty<KeyValuePair<string, IEnumerable<string>>>()) (from header in request.Headers.Concat(request.Content?.Headers ?? Enumerable.Empty<KeyValuePair<string, IEnumerable<string>>>())
from headerValue in header.Value // There can be more than one value for each name from headerValue in header.Value // There can be more than one value for each name
select new[] { header.Key, headerValue }).ToList() select new[] { header.Key, headerValue }).ToList()
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Services.Temporary
} }
else else
{ {
var responseDescriptor = Json.Deserialize<ResponseDescriptor>(responseDescriptorJson); var responseDescriptor = JsonUtil.Deserialize<ResponseDescriptor>(responseDescriptorJson);
var responseContent = responseBodyText == null ? null : new StringContent(responseBodyText); var responseContent = responseBodyText == null ? null : new StringContent(responseBodyText);
var responseMessage = responseDescriptor.ToResponseMessage(responseContent); var responseMessage = responseDescriptor.ToResponseMessage(responseContent);
tcs.SetResult(responseMessage); tcs.SetResult(responseMessage);

View File

@ -3,10 +3,14 @@
namespace Microsoft.AspNetCore.Blazor namespace Microsoft.AspNetCore.Blazor
{ {
// TODO: Once we no longer need the Razor base class hacks, rename this from 'JsonUtil'
// to 'Json', because it's a better name. Currently we can't call it 'Json' because the
// fake Razor base class already has a property called 'Json'.
/// <summary> /// <summary>
/// Provides mechanisms for converting between .NET objects and JSON strings. /// Provides mechanisms for converting between .NET objects and JSON strings.
/// </summary> /// </summary>
public static class Json public static class JsonUtil
{ {
/// <summary> /// <summary>
/// Serializes the value as a JSON string. /// Serializes the value as a JSON string.