Skip to content

Commit 3dc7ceb

Browse files
committed
Refactor ExpressionExecutionContextExtensions module
Modified the GetInput methods to consider the case where the method is called within a composite activity, ensuring that only local variables have precedence over workflow input when executing within a composite activity.
1 parent 2f10ef9 commit 3dc7ceb

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,37 +319,39 @@ public static IEnumerable<Variable> EnumerateVariablesInScope(this ExpressionExe
319319
/// <summary>
320320
/// Returns the value of the specified input.
321321
/// </summary>
322-
/// <param name="expressionExecutionContext"></param>
322+
/// <param name="context"></param>
323323
/// <param name="name">The name of the input.</param>
324324
/// <typeparam name="T">The type of the input.</typeparam>
325325
/// <returns>The value of the specified input.</returns>
326-
public static T? GetInput<T>(this ExpressionExecutionContext expressionExecutionContext, string name)
326+
public static T? GetInput<T>(this ExpressionExecutionContext context, string name)
327327
{
328-
var value = expressionExecutionContext.GetInput(name);
328+
var value = context.GetInput(name);
329329
return value.ConvertTo<T>();
330330
}
331331

332332
/// <summary>
333333
/// Returns the value of the specified input.
334334
/// </summary>
335-
/// <param name="expressionExecutionContext"></param>
335+
/// <param name="context"></param>
336336
/// <param name="name">The name of the input.</param>
337337
/// <returns>The value of the specified input.</returns>
338-
public static object? GetInput(this ExpressionExecutionContext expressionExecutionContext, string name)
338+
public static object? GetInput(this ExpressionExecutionContext context, string name)
339339
{
340-
// If there's a variable in the current scope with the specified name, return that.
341-
var variable = expressionExecutionContext.GetVariable(name);
340+
if (context.IsInsideCompositeActivity())
341+
{
342+
// If there's a variable in the current scope with the specified name, return that.
343+
var variable = context.GetVariable(name);
342344

343-
if (variable != null)
344-
return variable.Get(expressionExecutionContext);
345+
if (variable != null)
346+
return variable.Get(context);
347+
}
345348

346349
// Otherwise, return the input.
347-
var workflowExecutionContext = expressionExecutionContext.GetWorkflowExecutionContext();
350+
var workflowExecutionContext = context.GetWorkflowExecutionContext();
348351
var input = workflowExecutionContext.Input;
349352
return input.TryGetValue(name, out var value) ? value : default;
350353
}
351-
352-
354+
353355
/// <summary>
354356
/// Returns the value of the specified input.
355357
/// </summary>

0 commit comments

Comments
 (0)