Table of Contents

Class ActivityDefinition

Namespace
Temporalio.Activities
Assembly
Temporalio.dll

Definition of an activity.

public class ActivityDefinition
Inheritance
ActivityDefinition
Inherited Members

Properties

Name

Gets the activity name.

public string Name { get; }

Property Value

string

ParameterTypes

Gets the parameter types for the definition. This is used by the activity worker to know what to deserialize input values into.

public IReadOnlyCollection<Type> ParameterTypes { get; }

Property Value

IReadOnlyCollection<Type>

RequiredParameterCount

Gets the number of parameters required to be sent to InvokeAsync(object?[]). Activity invocation will fail if fewer are given.

public int RequiredParameterCount { get; }

Property Value

int

ReturnType

Gets the return type for the definition. This may be a Task for async activities. This is currently unused (callers are expected to provide the return type as needed).

public Type ReturnType { get; }

Property Value

Type

Methods

Create(Delegate, bool)

Create an activity definition from a delegate. DynamicInvoke(params object[]) is called on this delegate. The delegate must have an associated method and that method must have ActivityAttribute set on it.

public static ActivityDefinition Create(Delegate del, bool cache = true)

Parameters

del Delegate

Delegate to create definition from.

cache bool

True if this should cache the result making successive invocations for the same method quicker.

Returns

ActivityDefinition

Definition built from the delegate.

Create(string, Type, IReadOnlyCollection<Type>, int, Func<object?[], object?>)

Create an activity definition manually from the given values.

public static ActivityDefinition Create(string name, Type returnType, IReadOnlyCollection<Type> parameterTypes, int requiredParameterCount, Func<object?[], object?> invoker)

Parameters

name string

Name to use for the activity.

returnType Type

Return type of the activity. This is currently unused.

parameterTypes IReadOnlyCollection<Type>

Parameter types for the invoker.

requiredParameterCount int

Minimum number of parameters that must be provided to the invoker.

invoker Func<object[], object>

Function to call on activity invocation.

Returns

ActivityDefinition

Definition built from the given pieces.

CreateAll(Type, object?, bool)

Create all applicable activity definitions for the given type. At least one activity definition must exist.

public static IReadOnlyCollection<ActivityDefinition> CreateAll(Type type, object? instance, bool cache = true)

Parameters

type Type

Type with activity definitions.

instance object

Instance to invoke the activity definitions on. Must be non-null if any activities are non-static.

cache bool

True if each definition should be cached.

Returns

IReadOnlyCollection<ActivityDefinition>

Collection of activity definitions on the type.

CreateAll<T>(T?, bool)

Create all applicable activity definitions for the given type. At least one activity definition must exist.

public static IReadOnlyCollection<ActivityDefinition> CreateAll<T>(T? instance, bool cache = true)

Parameters

instance T

Instance to invoke the activity definitions on. Must be non-null if any activities are non-static.

cache bool

True if each definition should be cached.

Returns

IReadOnlyCollection<ActivityDefinition>

Collection of activity definitions on the type.

Type Parameters

T

Type with activity definitions.

InvokeAsync(object?[])

Invoke this activity with the given parameters. Before calling this, callers should have already validated that the parameters match ParameterTypes and there are at least RequiredParameterCount parameters. If the activity returns a Task, it is waited on and the result is extracted. If it is an untyped Task, the successful result will be Task<ValueTuple>.

public Task<object?> InvokeAsync(object?[] parameters)

Parameters

parameters object[]

Parameters for the call.

Returns

Task<object>

Task for result.

NameFromMethod(MethodInfo)

Gets the activity name from the given ActivityAttribute method.

public static string NameFromMethod(MethodInfo method)

Parameters

method MethodInfo

Method to get name from.

Returns

string

Name.

Exceptions

ArgumentException

If method does not have ActivityAttribute.