using DotnetStandardStreams; using Console = System.Console; namespace DotnetStandardStreamsApp; /// /// Typical command line for testing in PowerShell: /// @(1,2,3,4,5,6,7,8,9,10) | .\DotnetStandardStreamsApp.exe .\input.txt /// public static class Program { public static void Main(string[] args) { ITextSource textSource; IOutputTarget textTarget = new ConsoleOutputTarget(); if (args.Length > 0) textSource = new FileTextSource(args[0]); else textSource = new StdInTextSource(); Console.WriteLine("---- ExecuteAll"); ExecuteAll( textSource, textTarget); //Console.WriteLine("---- ExecuteAction"); //ExecuteAction( // textSource, // textTarget); //Console.WriteLine("---- ExecuteWhileNotEof"); //ExecuteWhileNotEof( // textSource, // textTarget); //Console.WriteLine("---- ExecuteForNotEof"); //ExecuteForNotEof( // textSource, // textTarget); } private static void ExecuteWhileNotEof(ITextSource source, IOutputTarget target) { source.Open(); target.Open(); while (!source.Eof()) { string thisLine = source.Read(); target.Output(thisLine); } target.Close(); source.Close(); } private static void ExecuteForNotEof(ITextSource source, IOutputTarget target) { source.Open(); target.Open(); for (string line = source.Read(); !source.Eof(); line = source.Read()) target.Output(line); target.Close(); source.Close(); } private static void ExecuteAction(ITextSource source, IOutputTarget target) { source.Open(); target.Open(); source.ReadAll(target.Output); target.Close(); source.Close(); } private static void ExecuteAll(ITextSource source, IOutputTarget target) { source.Open(); target.Open(); foreach (string line in source.ReadAll()) target.Output(line); target.Close(); source.Close(); } }