Method EvaluateAsync
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
stringThe C# code to evaluate. This cannot be null or empty.
options
objectOptional script options to configure the evaluation, such as references and imports. Can be null.
globalObject
objectAn optional object to provide global variables or state to the script. Can be null.
globalType
TypeThe type of the global object, if specified. Can be null.
cancellationToken
CancellationTokenA 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
.