Exemplo n.º 1
0
        /// <summary> Execute <paramref name="alternate"/> pipe, if the condition is true </summary>
        public static IBuilder <TIn, TOut> UseChoice <TIn, TOut>(
            this IBuilder <TIn, TOut> builder,
            [NotNull] Func <IContext, TOut, bool> condition,
            [NotNull] Delegated.Pipe <TOut> alternate,
            string?conditionDescription = null)
        {
            var tb = Pipe.Builder <TOut>().UseAsync(alternate);

            return(builder.UseChoice(condition, tb, conditionDescription));
        }
Exemplo n.º 2
0
        /// <summary> Execute extra step in the <paramref name="branch"/> if the condition is true, else skip it and continue executing the pipe </summary>
        public static IBuilder <TIn, TOut> UseBranch <TIn, TOut>(
            this IBuilder <TIn, TOut> builder,
            [NotNull] Func <IContext, TOut, bool> condition,
            [NotNull] Delegated.Pipe <TOut> branch,
            string?conditionDescription = null)
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            if (branch == null)
            {
                throw new ArgumentNullException(nameof(branch));
            }

            var tb = Pipe.Builder <TOut>().UseAsync(branch);

            return(builder.UseBranch(condition, tb, Builder.Unit <TOut>(), conditionDescription));
        }