Class ReflectionCallTask
Task that invokes a method via reflection, supporting argument resolution and optional main-thread dispatching via injected abstractions.
Implements
Inherited Members
Namespace: Serenity.Tasking.Application.Tasks
Assembly: Serenity.Global.Application.dll
Syntax
public class ReflectionCallTask : ITask
Constructors
ReflectionCallTask(string, TaskCriticality, float, string, string, bool, bool, IReadOnlyList<string>, ITaskServices, IReadOnlyList<string>, ILogService, IInstanceActivator, IMainThreadDispatcher)
Initializes a new instance of the ReflectionCallTask class.
Declaration
public ReflectionCallTask(string id, TaskCriticality criticality, float weight, string typeName, string methodName, bool resolveFromServices, bool isStatic, IReadOnlyList<string> stringArgs, ITaskServices services, IReadOnlyList<string> methodParamTypes, ILogService logService, IInstanceActivator instanceActivator = null, IMainThreadDispatcher mainThreadDispatcher = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | Unique identifier for the task. |
| TaskCriticality | criticality | Criticality level of the task. |
| float | weight | Weight of the task, influencing its scheduling and resource allocation. |
| string | typeName | The name of the type containing the method to invoke. |
| string | methodName | The name of the method to invoke. |
| bool | resolveFromServices | If true, the method's parameters will be resolved from the service container. |
| bool | isStatic | Indicates whether the method to invoke is static. |
| IReadOnlyList<string> | stringArgs | List of string arguments to pass to the method. |
| ITaskServices | services | Service container for resolving dependencies. |
| IReadOnlyList<string> | methodParamTypes | List of parameter type names for the method to invoke. |
| ILogService | logService | Optional logging service for warnings and errors. |
| IInstanceActivator | instanceActivator | Optional activator for creating type instances. Defaults to DefaultInstanceActivator. |
| IMainThreadDispatcher | mainThreadDispatcher | Optional dispatcher for main-thread execution requirements. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if id is null. |
Properties
Criticality
Criticality level of the task.
Declaration
public TaskCriticality Criticality { get; }
Property Value
| Type | Description |
|---|---|
| TaskCriticality | The criticality level. |
Id
Unique identifier for the task.
Declaration
public string Id { get; }
Property Value
| Type | Description |
|---|---|
| string | The unique identifier as a string. |
LastError
Gets the last error that occurred during task execution, if any.
Declaration
public Exception LastError { get; }
Property Value
| Type | Description |
|---|---|
| Exception | The last exception encountered, or null if none. |
Weight
Weight of the task, influencing its scheduling and resource allocation.
Declaration
public float Weight { get; }
Property Value
| Type | Description |
|---|---|
| float | The weight of the task. |
Methods
ReportTypeResolutionFailure(string)
Reports a type resolution failure. Override in subclasses for runtime-specific diagnostics (e.g. Unity console output).
Declaration
protected virtual void ReportTypeResolutionFailure(string diagnostics)
Parameters
| Type | Name | Description |
|---|---|---|
| string | diagnostics | The diagnostic information about the failure. |
RunAsync(CancellationToken)
Runs the reflection call task asynchronously.
Declaration
public Task RunAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Cancellation token to cancel the task. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | Thrown if the operation is canceled. |
| InvalidOperationException | Thrown if the specified type is not found. |
| MissingMethodException | Thrown if the specified method is not found. |
| TargetInvocationException | Thrown if the invoked method throws an exception. |
| Exception | Thrown if any other error occurs during method resolution or invocation. |
ShouldCreateInstanceOnSpecialContext(Type)
Determines whether instance creation for the given type requires dispatching to a special context (e.g. the main thread). Override in subclasses to apply runtime-specific policies.
Declaration
protected virtual bool ShouldCreateInstanceOnSpecialContext(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to instantiate. |
Returns
| Type | Description |
|---|---|
| bool | True if instance creation requires a special context; false otherwise. |
ShouldInvokeOnSpecialContext(MethodInfo, Type)
Determines whether the reflected method invocation requires dispatching to a special context (e.g. the main thread). Override in subclasses to apply runtime-specific policies. The base implementation delegates to the dispatcher if available.
Declaration
protected virtual bool ShouldInvokeOnSpecialContext(MethodInfo method, Type targetType)
Parameters
| Type | Name | Description |
|---|---|---|
| MethodInfo | method | The method to invoke. |
| Type | targetType | The type that declares the method. |
Returns
| Type | Description |
|---|---|
| bool | True if the invocation requires a special context; false otherwise. |