Table of Contents

Class IJSRuntimeExtensions

Namespace
MudBlazor
Assembly
MudBlazor.dll

Provides extension methods for IJSRuntime to handle JavaScript interop calls with error handling.

public static class IJSRuntimeExtensions
Inheritance
IJSRuntimeExtensions
Inherited Members

Methods

InvokeAsyncWithErrorHandling<TValue>(IJSRuntime, string, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException. In case an exception occured the default value of TValue is returned

public static ValueTask<(bool success, TValue value)> InvokeAsyncWithErrorHandling<TValue>(this IJSRuntime jsRuntime, string identifier, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

args object[]

JSON-serializable arguments.

Returns

ValueTask<(bool success, TValue value)>

An instance of TValue obtained by JSON-deserializing the return value into a tuple. The first item (sucess) is true in case where there was no exception, otherwise fall.

Type Parameters

TValue

The JSON-serializable return type.

InvokeAsyncWithErrorHandling<TValue>(IJSRuntime, string, CancellationToken, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException. In case an exception occured the default value of TValue is returned

public static ValueTask<(bool success, TValue value)> InvokeAsyncWithErrorHandling<TValue>(this IJSRuntime jsRuntime, string identifier, CancellationToken cancellationToken, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

cancellationToken CancellationToken

A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts (DefaultAsyncTimeout) from being applied.

args object[]

JSON-serializable arguments.

Returns

ValueTask<(bool success, TValue value)>

An instance of TValue obtained by JSON-deserializing the return value into a tuple. The first item (sucess) is true in case where there was no exception, otherwise fall.

Type Parameters

TValue

The JSON-serializable return type.

InvokeAsyncWithErrorHandling<TValue>(IJSRuntime, TValue, string, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask<(bool success, TValue value)> InvokeAsyncWithErrorHandling<TValue>(this IJSRuntime jsRuntime, TValue fallbackValue, string identifier, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

fallbackValue TValue

The value that should be returned in case an exception occured

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

args object[]

JSON-serializable arguments.

Returns

ValueTask<(bool success, TValue value)>

An instance of TValue obtained by JSON-deserializing the return value into a tuple. The first item (sucess) is true in case where there was no exception, otherwise fall.

Type Parameters

TValue

The JSON-serializable return type.

InvokeAsyncWithErrorHandling<TValue>(IJSRuntime, TValue, string, CancellationToken, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask<(bool success, TValue value)> InvokeAsyncWithErrorHandling<TValue>(this IJSRuntime jsRuntime, TValue fallbackValue, string identifier, CancellationToken cancellationToken, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

fallbackValue TValue

The value that should be returned in case an exception occured

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

cancellationToken CancellationToken

A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts (DefaultAsyncTimeout) from being applied.

args object[]

JSON-serializable arguments.

Returns

ValueTask<(bool success, TValue value)>

An instance of TValue obtained by JSON-deserializing the return value into a tuple. The first item (sucess) is true in case where there was no exception, otherwise fall.

Type Parameters

TValue

The JSON-serializable return type.

InvokeVoidAsyncIgnoreErrors(IJSRuntime, string, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask InvokeVoidAsyncIgnoreErrors(this IJSRuntime jsRuntime, string identifier, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

args object[]

JSON-serializable arguments.

Returns

ValueTask

A ValueTask that represents the asynchronous invocation operation.

InvokeVoidAsyncIgnoreErrors(IJSRuntime, string, CancellationToken, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask InvokeVoidAsyncIgnoreErrors(this IJSRuntime jsRuntime, string identifier, CancellationToken cancellationToken, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

cancellationToken CancellationToken

A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts (DefaultAsyncTimeout) from being applied.

args object[]

JSON-serializable arguments.

Returns

ValueTask

A ValueTask that represents the asynchronous invocation operation.

InvokeVoidAsyncWithErrorHandling(IJSRuntime, string, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask<bool> InvokeVoidAsyncWithErrorHandling(this IJSRuntime jsRuntime, string identifier, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

args object[]

JSON-serializable arguments.

Returns

ValueTask<bool>

A ValueTask that represents the asynchronous invocation operation and resolves to true in case no exception has occured otherwise false.

InvokeVoidAsyncWithErrorHandling(IJSRuntime, string, CancellationToken, params object[])

Invokes the specified JavaScript function asynchronously and catches JSException, JSDisconnectedException and TaskCanceledException

public static ValueTask<bool> InvokeVoidAsyncWithErrorHandling(this IJSRuntime jsRuntime, string identifier, CancellationToken cancellationToken, params object[] args)

Parameters

jsRuntime IJSRuntime

The IJSRuntime.

identifier string

An identifier for the function to invoke. For example, the value "someScope.someFunction" will invoke the function window.someScope.someFunction.

cancellationToken CancellationToken

A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts (DefaultAsyncTimeout) from being applied.

args object[]

JSON-serializable arguments.

Returns

ValueTask<bool>

A ValueTask that represents the asynchronous invocation operation and resolves to true in case no exception has occured otherwise false.