Add non-generic GetVariable method and Python accessors

A non-generic version of GetVariable method has been added to the ExecutionContextProxy.cs, allowing direct access to variables without specifying a type. To leverage this, Python accessors for getting and setting workflow variables have been added to GenerateWorkflowVariableAccessors.cs. This enhances the interaction between the Python scripts and the context variables.
This commit is contained in:
Sipke Schoorstra 2023-12-28 14:18:07 +01:00
parent 511f5b5aaf
commit 0bf562f72c
2 changed files with 11 additions and 0 deletions

View file

@ -23,6 +23,12 @@ public class GenerateWorkflowVariableAccessors : INotificationHandler<Evaluating
sb.AppendLine(" def __init__(self, execution_context):");
sb.AppendLine(" self.execution_context = execution_context");
sb.AppendLine();
sb.AppendLine(" def get(self, name):");
sb.AppendLine(" return self.execution_context.GetVariable(name)");
sb.AppendLine();
sb.AppendLine(" def set(self, name, value):");
sb.AppendLine(" self.execution_context.SetVariable(name, value)");
sb.AppendLine();
foreach (var variable in variables)
{

View file

@ -28,6 +28,11 @@ public partial class ExecutionContextProxy
/// Gets the value of the specified variable.
/// </summary>
public object? GetVariable<T>(string name) => ExpressionExecutionContext.GetVariableInScope(name).ConvertTo<T>();
/// <summary>
/// Gets the value of the specified variable.
/// </summary>
public object? GetVariable(string name) => ExpressionExecutionContext.GetVariableInScope(name);
/// <summary>
/// Sets the value of the specified variable.