Skip to content

Commit afeab33

Browse files
authored
Add Json StringSyntaxAttribute syntaxes (#44641)
1 parent 76c7670 commit afeab33

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected WebAssemblyJSRuntime()
2323
}
2424

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

4444
/// <inheritdoc />
45-
protected override void BeginInvokeJS(long asyncHandle, string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId)
45+
protected override void BeginInvokeJS(long asyncHandle, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId)
4646
{
4747
var callInfo = new JSCallInfo
4848
{

src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class DotNetDispatcher
4242
/// <param name="argsJson">A JSON representation of the parameters.</param>
4343
/// <returns>A JSON representation of the return value, or null.</returns>
4444
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")]
45-
public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, string argsJson)
45+
public static string? Invoke(JSRuntime jsRuntime, in DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson)
4646
{
4747
// This method doesn't need [JSInvokable] because the platform is responsible for having
4848
// some way to dispatch calls here. The logic inside here is the thing that checks whether
@@ -72,7 +72,7 @@ public static class DotNetDispatcher
7272
/// <param name="argsJson">A JSON representation of the parameters.</param>
7373
/// <returns>A JSON representation of the return value, or null.</returns>
7474
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect application code is configured to ensure return types of JSInvokable methods are retained.")]
75-
public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, string argsJson)
75+
public static void BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, [StringSyntax(StringSyntaxAttribute.Json)] string argsJson)
7676
{
7777
// This method doesn't need [JSInvokable] because the platform is responsible for having
7878
// some way to dispatch calls here. The logic inside here is the thing that checks whether

src/JSInterop/Microsoft.JSInterop/src/JSInProcessRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime
5151
/// <param name="identifier">The identifier for the function to invoke.</param>
5252
/// <param name="argsJson">A JSON representation of the arguments.</param>
5353
/// <returns>A JSON representation of the result.</returns>
54-
protected virtual string? InvokeJS(string identifier, string? argsJson)
54+
protected virtual string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson)
5555
=> InvokeJS(identifier, argsJson, JSCallResultType.Default, 0);
5656

5757
/// <summary>
@@ -62,5 +62,5 @@ public abstract class JSInProcessRuntime : JSRuntime, IJSInProcessRuntime
6262
/// <param name="resultType">The type of result expected from the invocation.</param>
6363
/// <param name="targetInstanceId">The instance ID of the target JS object.</param>
6464
/// <returns>A JSON representation of the result.</returns>
65-
protected abstract string? InvokeJS(string identifier, string? argsJson, JSCallResultType resultType, long targetInstanceId);
65+
protected abstract string? InvokeJS(string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson, JSCallResultType resultType, long targetInstanceId);
6666
}

src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void CleanupTasksAndRegistrations(long taskId)
154154
/// <param name="taskId">The identifier for the function invocation, or zero if no async callback is required.</param>
155155
/// <param name="identifier">The identifier for the function to invoke.</param>
156156
/// <param name="argsJson">A JSON representation of the arguments.</param>
157-
protected virtual void BeginInvokeJS(long taskId, string identifier, string? argsJson)
157+
protected virtual void BeginInvokeJS(long taskId, string identifier, [StringSyntax(StringSyntaxAttribute.Json)] string? argsJson)
158158
=> BeginInvokeJS(taskId, identifier, argsJson, JSCallResultType.Default, 0);
159159

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

170170
/// <summary>
171171
/// Completes an async JS interop call from JavaScript to .NET

0 commit comments

Comments
 (0)