private static void Run(IInstructionHandler handler, List<Cell> cells, Action<ExecutionContext> before, Action<ExecutionContext, string> after, SecureRandom randomizer, TextReader reader) { using (var writer = new StringWriter(CultureInfo.CurrentCulture)) { using (reader) { var context = new ExecutionContext(cells, reader, writer, randomizer); before?.Invoke(context); handler.Handle(context); var result = writer.GetStringBuilder().ToString(); after?.Invoke(context, result); } } }