Skip to content

Add Json StringSyntaxAttribute syntaxes #44641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected WebAssemblyJSRuntime()
}

/// <inheritdoc />
protected override string InvokeJS(string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId)
protected override string InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId)
{
var callInfo = new JSCallInfo
{
Expand All @@ -42,7 +42,7 @@ protected override string InvokeJS(string identifier, string? argsJson, JSCallRe
}

/// <inheritdoc />
protected override void BeginInvokeJS(long asyncHandle, string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId)
protected override void BeginInvokeJS(long asyncHandle, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId)
{
var callInfo = new JSCallInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static class DotNetDispatcher
/// <param name="argsJson">A JSON representation of the parameters.</param>
/// <returns>A JSON representation of the return value, or null.</returns>
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")]
public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, string argsJson)
public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson)
{
// This method doesn't need [JSInvokable] because the platform is responsible for having
// some way to dispatch calls here. The logic inside here is the thing that checks whether
Expand Down Expand Up @@ -72,7 +72,7 @@ public static class DotNetDispatcher
/// <param name="argsJson">A JSON representation of the parameters.</param>
/// <returns>A JSON representation of the return value, or null.</returns>
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")]
public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, string argsJson)
public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson)
{
// This method doesn't need [JSInvokable] because the platform is responsible for having
// some way to dispatch calls here. The logic inside here is the thing that checks whether
Expand Down
4 changes: 2 additions & 2 deletions src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime
/// <param name="identifier">The identifier for the function to invoke.</param>
/// <param name="argsJson">A JSON representation of the arguments.</param>
/// <returns>A JSON representation of the result.</returns>
protected virtual string? InvokeJS(string identifier, string? argsJson)
protected virtual string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson)
=> InvokeJS(identifier, argsJson, JSCallResultType.Default, 0);

/// <summary>
Expand All @@ -62,5 +62,5 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime
/// <param name="resultType">The type of result expected from the invocation.</param>
/// <param name="targetInstanceId">The instance ID of the target JS object.</param>
/// <returns>A JSON representation of the result.</returns>
protected abstract string? InvokeJS(string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId);
protected abstract string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId);
}
4 changes: 2 additions & 2 deletions src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void CleanupTasksAndRegistrations(long taskId)
/// <param name="taskId">The identifier for the function invocation, or zero if no async callback is required.</param>
/// <param name="identifier">The identifier for the function to invoke.</param>
/// <param name="argsJson">A JSON representation of the arguments.</param>
protected virtual void BeginInvokeJS(long taskId, string identifier, string? argsJson)
protected virtual void BeginInvokeJS(long taskId, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson)
=> BeginInvokeJS(taskId, identifier, argsJson, JSCallResultType.Default, 0);

/// <summary>
Expand All @@ -165,7 +165,7 @@ protected virtual void BeginInvokeJS(long taskId, string identifier, string? arg
/// <param name="argsJson">A JSON representation of the arguments.</param>
/// <param name="resultType">The type of result expected from the invocation.</param>
/// <param name="targetInstanceId">The instance ID of the target JS object.</param>
protected abstract void BeginInvokeJS(long taskId, string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId);
protected abstract void BeginInvokeJS(long taskId, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId);

/// <summary>
/// Completes an async JS interop call from JavaScript to .NET
Expand Down