public static ICommandBuilder <T> Add <T>(this ICommandBuilder <T> builder, AsyncContextHandler <T> action) =>
        builder.Add(new AsyncCommand <T>(async(c, ct) =>
        {
            await action(c, ct).ConfigureAwait(false);

            return(c);
        }).ToSync());
        public static ICommandBuilder <T> Add <T>(this ICommandBuilder <T> builder, Action <T, CancellationToken> action) =>
        builder.Add(new Command <T>((c, ct) =>
        {
            action(c, ct);

            return(c);
        }));
        public static ICommandBuilder <T> Add <T>(this ICommandBuilder <T> builder, Action <T> action) =>
        builder.Add(new Command <T>(i =>
        {
            action(i);

            return(i);
        }));
示例#4
0
        /// <summary>
        /// Adds <paramref name="command"/> to the builder <paramref name="iterations"/> times.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="iterations"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static ICommandBuilder <IRobot> Repeat(this ICommandBuilder <IRobot> builder, int iterations, ICommand <IRobot> command)
        {
            for (var iteration = 0; iteration < iterations; iteration++)
            {
                builder.Add(command);
            }

            return(builder);
        }
        public static ICommandBuilder <T> AddIf <T>(this ICommandBuilder <T> builder, Predicate <T> predicate, Action <T, CancellationToken> action) =>
        builder.Add(new Command <T>((i, ct) =>
        {
            if (predicate(i))
            {
                action(i, ct);
            }

            return(i);
        }));
        public static ICommandBuilder <T> AddIf <T>(this ICommandBuilder <T> builder, Predicate <T> predicate, Action <T> action) =>
        builder.Add(new Command <T>(i =>
        {
            if (predicate(i))
            {
                action(i);
            }

            return(i);
        }));
示例#7
0
 public static ICommandBuilder <IRobot> Place(this ICommandBuilder <IRobot> builder, IPlacement placement)
 => builder.Add(new PlaceCommand(placement));
示例#8
0
 public static ICommandBuilder <IRobot> TurnRight(this ICommandBuilder <IRobot> builder)
 => builder.Add(new TurnRightCommand());
示例#9
0
 public static ICommandBuilder <IRobot> MoveForward(this ICommandBuilder <IRobot> builder)
 => builder.Add(new MoveForwardCommand());
示例#10
0
 public static ICommandBuilder <IRobot> Report(this ICommandBuilder <IRobot> builder, Action <IPlacement> callback)
 => builder.Add(new ReportCommand(callback));
 public static ICommandBuilder <T> Add <T>(this ICommandBuilder <T> builder, Func <T, T> action) =>
 builder.Add(new Command <T>(action));
 public static ICommandBuilder <T> Add <T>(this ICommandBuilder <T> builder, AsyncContextTransformation <T> transformation) =>
 builder.Add(new AsyncCommand <T>(transformation).ToSync());
 public static ICommandBuilder <T> AddIf <T>(this ICommandBuilder <T> builder, Predicate <T> predicate, Func <T, T> action) =>
 builder.Add(new Command <T>(i => predicate(i) ? action(i) : i));