@using Microsoft.JSInterop
@using BasicTestApp.InteropTest
@using System.Runtime.InteropServices
Invocations
@foreach (var invocation in Invocations)
{
@invocation.Key
@invocation.Value
}
.NET to JS calls: passing .NET object by ref, receiving .NET object by ref
@foreach (var kvp in ReceiveDotNetObjectByRefResult)
{
@(kvp.Key)Sync
@kvp.Value
}
@foreach (var kvp in ReceiveDotNetObjectByRefAsyncResult)
{
@(kvp.Key)Async
@kvp.Value
}
Return values and exceptions thrown from .NET
@foreach (var returnValue in ReturnValues)
{
@returnValue.Key
@returnValue.Value
}
Exceptions thrown from JavaScript
@nameof(ExceptionFromSyncMethod)
@ExceptionFromSyncMethod?.Message
@nameof(SyncExceptionFromAsyncMethod)
@SyncExceptionFromAsyncMethod?.Message
@nameof(AsyncExceptionFromAsyncMethod)
@AsyncExceptionFromAsyncMethod?.Message
@if (DoneWithInterop)
{
Done with interop.
}
@functions {
public IDictionary ReturnValues { get; set; } = new Dictionary();
public IDictionary Invocations { get; set; } = new Dictionary();
public JSException ExceptionFromSyncMethod { get; set; }
public JSException SyncExceptionFromAsyncMethod { get; set; }
public JSException AsyncExceptionFromAsyncMethod { get; set; }
public IDictionary ReceiveDotNetObjectByRefResult { get; set; } = new Dictionary();
public IDictionary ReceiveDotNetObjectByRefAsyncResult { get; set; } = new Dictionary();
public bool DoneWithInterop { get; set; }
public async Task InvokeInteropAsync()
{
var shouldSupportSyncInterop = RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY"));
var testDTOTOPassByRef = new TestDTO(nonSerializedValue: 123);
var instanceMethodsTarget = new JavaScriptInterop();
Console.WriteLine("Starting interop invocations.");
await JSRuntime.Current.InvokeAsync