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
codestringThe C# code to evaluate. This cannot be null or empty.
optionsobjectOptional script options to configure the evaluation, such as references and imports. Can be null.
globalObjectobjectAn optional object to provide global variables or state to the script. Can be null.
globalTypeTypeThe type of the global object, if specified. Can be null.
cancellationTokenCancellationTokenA 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
TThe 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.