diff --git a/src/WorkflowCore/Interface/IStepBuilder.cs b/src/WorkflowCore/Interface/IStepBuilder.cs index e20d585c5..945c984c5 100644 --- a/src/WorkflowCore/Interface/IStepBuilder.cs +++ b/src/WorkflowCore/Interface/IStepBuilder.cs @@ -89,6 +89,7 @@ public interface IStepBuilder : IWorkflowModifier /// IStepBuilder Output(Expression> dataProperty, Expression> value); + IStepBuilder Output(Expression> dataProperty, Expression> value); /// /// Manipulate properties on the data object after the step executes @@ -96,6 +97,7 @@ public interface IStepBuilder : IWorkflowModifier /// IStepBuilder Output(Action action); + IStepBuilder Output(Action action); IStepBuilder End(string name) where TStep : IStepBody; diff --git a/src/WorkflowCore/Models/MemberMapParameter.cs b/src/WorkflowCore/Models/MemberMapParameter.cs index e5273986d..1b1f902e8 100644 --- a/src/WorkflowCore/Models/MemberMapParameter.cs +++ b/src/WorkflowCore/Models/MemberMapParameter.cs @@ -43,8 +43,9 @@ private void Assign(object sourceObject, LambdaExpression sourceExpr, object tar } var valueExpr = Expression.Convert(Expression.Constant(resolvedValue), targetExpr.ReturnType); - var assign = Expression.Lambda(Expression.Assign(targetExpr.Body, valueExpr), targetExpr.Parameters.Single()); - assign.Compile().DynamicInvoke(targetObject); + var assign = Expression.Lambda(Expression.Assign(targetExpr.Body, valueExpr), targetExpr.Parameters); + if( targetExpr.Parameters.Count == 1 ) assign.Compile( ).DynamicInvoke( targetObject ); + else assign.Compile( ).DynamicInvoke( targetObject, context ); } public void AssignInput(object data, IStepBody body, IStepExecutionContext context) diff --git a/src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs b/src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs index 9e41f15ca..6ca3142de 100644 --- a/src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs +++ b/src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs @@ -163,12 +163,24 @@ public IStepBuilder Output(Expression Output(Expression> dataProperty, Expression> value) + { + Step.Outputs.Add(new MemberMapParameter(value, dataProperty)); + return this; + } + public IStepBuilder Output(Action action) { Step.Outputs.Add(new ActionParameter(action)); return this; } + public IStepBuilder Output(Action action) + { + Step.Outputs.Add(new ActionParameter(action)); + return this; + } + public IStepBuilder WaitFor(string eventName, Expression> eventKey, Expression> effectiveDate = null, Expression> cancelCondition = null) { var newStep = new WorkflowStep(); diff --git a/test/WorkflowCore.UnitTests/Models/MemberMapParameterTests.cs b/test/WorkflowCore.UnitTests/Models/MemberMapParameterTests.cs index 81e667139..e11997340 100644 --- a/test/WorkflowCore.UnitTests/Models/MemberMapParameterTests.cs +++ b/test/WorkflowCore.UnitTests/Models/MemberMapParameterTests.cs @@ -44,6 +44,23 @@ public void should_assign_output() data.Value1.Should().Be(step.Value1); } + [Fact] + public void should_assign_output_with_context() + { + Expression> memberExpr = (x => x.Value2); + Expression> valueExpr = ((step, context) => ((string[])step.Value2)[(int)context.Item]); + var subject = new MemberMapParameter(valueExpr, memberExpr); + var data = new MyData(); + var step = new MyStep { + Value2 = new []{"A", "B", "C", "D"} + }; + + var context = new StepExecutionContext {Item = 2}; + + subject.AssignOutput(data, step, context); + + data.Value2.Should().Be("C"); + } [Fact] public void should_convert_input()