How can I access SyntheticProperties from ExecuteAsync() method of my activity? #5764
Replies: 2 comments 3 replies
-
To access the values in a type-safe manner with expression evaluation, you can use the Here's an example of how you might use it: public class MyCustomActivity : Activity
{
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
public MyCustomActivity(IWorkflowExpressionEvaluator expressionEvaluator)
{
_expressionEvaluator = expressionEvaluator;
}
protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
{
// Assuming you have a synthetic property called "MyExpressionProperty"
var expression = context.GetInput<string>("MyExpressionProperty");
var type = typeof(MyExpectedType); // Replace with the expected type of the result
// Evaluate the expression
var result = await _expressionEvaluator.EvaluateAsync(expression, type, context, context.CancellationToken);
// Use the result
var typedResult = (MyExpectedType)result; // Cast to the expected type
// Continue with your activity logic...
}
} In this example, Please note that you will need to inject the If you are using Elsa 2.0 or later, you might also consider using the Remember to handle any potential exceptions that might occur during expression evaluation, such as syntax errors or type mismatches. If you need further assistance or if this approach does not fit your scenario, please provide more details about your custom This comment was generated by Glime. |
Beta Was this translation helpful? Give feedback.
-
Hello @sleepysimon89 , I do have a same scenario, where I have created a custom activity like as below:
I have created ActivityProvider class as below and registered with elsa services.
|
Beta Was this translation helpful? Give feedback.
-
Hello together,
I build some activities on runtime using a custom ActivityProvider implementation. The necessary inputs are defined on runtime.
I get the values in the SyntheticProperties dictionary during execution of the activity and I can access them using the following code:
But this only works for literals. Is there any possibility to access it typesafe with expression evaluated?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions