Skip to content

Conversation

@boma96
Copy link
Collaborator

@boma96 boma96 commented Apr 16, 2025

Implement the feature as described in #199.

Since ConductorSharp can not differentiate between the call to the function which formats the conductor expression and standard expression which library tries to evaluate we had to introduce two new attributes for this to work: ConductorExpressionFormatter and FormatterParameter.

  • ConductorExpressionFormatter is applied on method we want to use for formatting
  • FormatterParameter is applied on method parameters which we expect to receive conductor expression arguments.

Formatter method must satisfy the following conditions:

  • Return type must be a string
  • FormatterParameter parameter type must be a string and corresponding argument must evaluate to a conductor expression.
  • All non FormatterParameter arguments should be evaluable
public class FormatterWorkflow : Workflow<FormatterWorkflow, FormatterWorkflowInput, FormatterWorkflowOutput>
{
    public class Library
    {
        public static Library Singleton { get; } = new();

        [ConductorExpressionFormatter]
        public string PrepareEmail([FormatterParameter] string firstName, [FormatterParameter] string lastName) =>
            $"{firstName}.{lastName}@example.com";

        [ConductorExpressionFormatter]
        public static string FormatName([FormatterParameter] string firstName, [FormatterParameter] string lastName, string prefix) =>
            $"{prefix} {firstName} {lastName}";
    }

    public EmailPrepareV1 EmailPrepare { get; set; }

    public FormatterWorkflow(WorkflowDefinitionBuilder<FormatterWorkflow, FormatterWorkflowInput, FormatterWorkflowOutput> builder)
        : base(builder) { }

    public override void BuildDefinition()
    {
        _builder.AddTask(
            wf => wf.EmailPrepare,
            wf =>
                new()
                {
                    Address = Library.Singleton.PrepareEmail(wf.Input.FirstName, wf.Input.LastName),
                    Name = Library.FormatName(wf.Input.FirstName, wf.Input.LastName, "Mr")
                }
        );
    }
}

@boma96 boma96 merged commit 7a159b4 into master Apr 23, 2025
1 check passed
@boma96 boma96 deleted the feat/master/conductor-expression-formatting branch April 23, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants