Added else to switch (#149)

Closes #136
This commit is contained in:
Andale-online 2019-11-14 10:06:02 +01:00 committed by Sipke Schoorstra
parent 3ea596cdba
commit cccf5c831d

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Attributes;
@ -21,10 +22,14 @@ namespace Elsa.Activities.ControlFlow.Activities
{
private readonly IWorkflowExpressionEvaluator expressionEvaluator;
public Switch(IWorkflowExpressionEvaluator expressionEvaluator)
{
this.expressionEvaluator = expressionEvaluator;
Cases = new List<string>();
Cases = new List<string>()
{
"default"
};
}
[ActivityProperty(Hint = "The expression to evaluate. The evaluated value will be used to switch on.")]
@ -46,7 +51,15 @@ namespace Elsa.Activities.ControlFlow.Activities
CancellationToken cancellationToken)
{
var result = await expressionEvaluator.EvaluateAsync(Expression, workflowContext, cancellationToken);
return Outcome(result);
if (Cases.Contains(result) || !Cases.Contains("default"))
{
return Outcome(result);
}
else
{
return Outcome("default");
}
}
}
}