Advertisement
elena1234

How to use stringBuilderWriter

Apr 28th, 2021
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. //In folder IO
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using WarCroft.Core.IO.Contracts;
  7.  
  8. namespace WarCroft.Core.IO
  9. {
  10.     public class StringBuilderWriter : IWriter
  11.     {
  12.         public StringBuilder sb = new StringBuilder();
  13.  
  14.         public void WriteLine(string message)
  15.         {
  16.             sb.AppendLine(message);
  17.         }
  18.     }
  19. }
  20.  
  21.  
  22. // in StartUp
  23.  
  24. using System;
  25. using WarCroft.Core;
  26. using WarCroft.Core.IO;
  27. using WarCroft.Core.IO.Contracts;
  28.  
  29. namespace WarCroft
  30. {
  31.     public class StartUp
  32.     {
  33.         public static void Main(string[] args)
  34.         {
  35.            // IReader reader = new ConsoleReader();
  36.            // IWriter writer = new ConsoleWriter();
  37.  
  38.            // var engine = new Engine(reader, writer);
  39.           //  engine.Run();
  40.  
  41.                 /* Use the below configuration instead of the usual one if you wish to print all output messages together after the inputs for easier comparison with the example output. */
  42.  
  43.             IReader reader = new ConsoleReader();
  44.             var sbWriter = new StringBuilderWriter();
  45.  
  46.             var engine = new Engine(reader, sbWriter);
  47.             engine.Run();
  48.             Console.WriteLine(sbWriter.sb.ToString().Trim());
  49.         }
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement