Table of Contents

Method EvaluateAsync

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

EvaluateAsync<T>(string, object?, object?, Type?, CancellationToken)

Evaluates the specified C# code asynchronously and returns the result as the specified type.

public static Task<T> EvaluateAsync<T>(string code, object? options = null, object? globalObject = null, Type? globalType = null, CancellationToken cancellationToken = default)

Parameters

code string

The C# code to evaluate. This cannot be null or empty.

options object

Optional script options to configure the evaluation, such as references and imports. Can be null.

globalObject object

An optional object to provide global variables or state to the script. Can be null.

globalType Type

The type of the global object, if specified. Can be null.

cancellationToken CancellationToken

A token to monitor for cancellation requests. Defaults to None.

Returns

Task<T>

A task that represents the asynchronous operation. The task result contains the evaluated value of type T.

Type Parameters

T

The type of the result expected from the evaluation.

Remarks

This method uses the Roslyn scripting API to evaluate the provided C# code. The evaluation is performed in an isolated scripting context, and the result is returned as the specified type T.