MassTransit / Automatonymous

A state machine library for .Net - 100% code - No doodleware
Apache License 2.0
736 stars 117 forks source link

Support for Else conditions #52

Closed johnkievlan closed 5 years ago

johnkievlan commented 5 years ago

You know what would be nice? IfElse :)

phatboyg commented 5 years ago

Yeah, that might be cool.

mattsve commented 5 years ago

Meanwhile this extension method could be of use.

public static EventActivityBinder<TInstance, TData> IfThenElse<TInstance, TData>(
        this EventActivityBinder<TInstance, TData> binder,
        StateMachineCondition<TInstance, TData> condition,
        Func<EventActivityBinder<TInstance, TData>, EventActivityBinder<TInstance, TData>> thenActivityCallback,
        Func<EventActivityBinder<TInstance, TData>, EventActivityBinder<TInstance, TData>> elseActivityCallback)
        where TInstance : class
    {
        var result = false;
        return binder.If(context => result = condition(context), thenActivityCallback).If(_ => !result, elseActivityCallback); 
    }
phatboyg commented 5 years ago

Fixed by #55