From 3cc80939c0defba0f19112d6507e2b81a5ca4bf9 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 28 Jan 2021 09:29:46 +0100 Subject: [PATCH] Add GetInput/GetOutput overloads accepting default value --- .../Services/Models/ActivityExecutionContext.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs b/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs index 6260d07af..36520429f 100644 --- a/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs +++ b/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs @@ -84,10 +84,17 @@ namespace Elsa.Services.Models var activityTypeService = ServiceScope.ServiceProvider.GetRequiredService(); return await activityTypeService.ActivateActivityAsync(ActivityBlueprint, cancellationToken); } - + public T? GetInput() => Input.ConvertTo(); + public T? GetInput(Func defaultValue) => Input != null ? Input.ConvertTo() : defaultValue(); + public T? GetInput(T? defaultValue) => Input != null ? Input.ConvertTo() : defaultValue; + public object? GetOutputFrom(string activityName) => WorkflowExecutionContext.GetOutputFrom(activityName); - public T GetOutputFrom(string activityName) => (T) GetOutputFrom(activityName)!; + public object? GetOutputFrom(string activityName, object? defaultValue) => WorkflowExecutionContext.GetOutputFrom(activityName) ?? defaultValue; + public object? GetOutputFrom(string activityName, Func defaultValue) => WorkflowExecutionContext.GetOutputFrom(activityName) ?? defaultValue(); + public T? GetOutputFrom(string activityName) => (T?) GetOutputFrom(activityName)!; + public T? GetOutputFrom(string activityName, Func defaultValue) => (T?) GetOutputFrom(activityName, defaultValue())!; + public T? GetOutputFrom(string activityName, T? defaultValue) => (T?) GetOutputFrom(activityName, () => defaultValue)!; public void SetWorkflowContext(object? value) => WorkflowExecutionContext.SetWorkflowContext(value); public T GetWorkflowContext() => WorkflowExecutionContext.GetWorkflowContext(); }