ComponentFunction Class

A function of the component model: a function exported by a component instance (ComponentFunction.Call), or a function of the host (ComponentFunction.FromCallback, ComponentFunction.FromAsyncCallback) given to the imports of a component.

public sealed class ComponentFunction

Properties

NameDescription
TypeGets the type of the function: the type of an exported function, or the type given to a function of the host (null when it takes the type of the import).

Gets the type of the function: the type of an exported function, or the type given to a function of the host (null when it takes the type of the import).

public ComponentFunctionType? Type { get; }

Methods

NameDescription
Call(ComponentValue[])Calls an exported function: the arguments are converted to the memory of the component, and the result from it. The call runs the store until it returns, including the other asynchronous calls of the store and the operations of the host they wait for.
FromAsyncCallback(ComponentHostAsyncCallback, ComponentFunctionType?)Creates an asynchronous function of the host: a component that calls it asynchronously continues while it runs. Without type, the function has the type of the import it is given to.
FromCallback(ComponentHostCallback, ComponentFunctionType?)Creates a function of the host. Without type, the function has the type of the import it is given to: the callback receives it in ComponentCallContext.Type.

Call(ComponentValue[])

WasmComponent.cs

Calls an exported function: the arguments are converted to the memory of the component, and the result from it. The call runs the store until it returns, including the other asynchronous calls of the store and the operations of the host they wait for.

public ComponentValue? Call(params ComponentValue[] arguments)

Parameters

arguments ComponentValue[]
The arguments, one per parameter.

Returns

ComponentValue? The result, or null for a function without result.

Exceptions

InvalidOperationException
The function is a function of the host.
WasmTrapException
The component trapped.

FromAsyncCallback(ComponentHostAsyncCallback, ComponentFunctionType?)

WasmComponent.cs

Creates an asynchronous function of the host: a component that calls it asynchronously continues while it runs. Without type, the function has the type of the import it is given to.

public static ComponentFunction FromAsyncCallback(ComponentHostAsyncCallback callback, ComponentFunctionType? type = null)

Parameters

callback ComponentHostAsyncCallback
The steps of the function.
type ComponentFunctionType?
The type of the function, which must be the type of the import, or null.

Returns

ComponentFunction

FromCallback(ComponentHostCallback, ComponentFunctionType?)

WasmComponent.cs

Creates a function of the host. Without type, the function has the type of the import it is given to: the callback receives it in ComponentCallContext.Type.

public static ComponentFunction FromCallback(ComponentHostCallback callback, ComponentFunctionType? type = null)

Parameters

callback ComponentHostCallback
The steps of the function.
type ComponentFunctionType?
The type of the function, which must be the type of the import, or null.

Returns

ComponentFunction