From 1d34d1b6b7b995838eb26cb42c909da9e40a4c89 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Mon, 29 Mar 2021 10:05:48 +1300 Subject: [PATCH] Removed/expanded targeted-type 'new' expressions for legacy portability --- Assignment 1/Program.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 2a1c538..f35253c 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -27,7 +27,7 @@ namespace Assignment_1 /// /// Characters that cannot appear in a normal string /// - static readonly List ForbiddenChars = new() + static readonly List ForbiddenChars = new List() { '$', '\\', @@ -45,8 +45,8 @@ namespace Assignment_1 bool exit = false; while (!exit) { - MemoryStream sourceStream = new(1024); - Parser parser = new(); + MemoryStream sourceStream = new MemoryStream(1024); + Parser parser = new Parser(); bool dynamicInput = false; // From https://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected // Reading from pipes is equivalent to reading user input, though the input is redirected @@ -78,7 +78,7 @@ namespace Assignment_1 Thread.Sleep(2000); Environment.Exit(0); } - ConsoleKeyInfo ck = new(); + ConsoleKeyInfo ck = new ConsoleKeyInfo(); while (ck.Key != ConsoleKey.Y && ck.Key != ConsoleKey.N) { Console.WriteLine("\nWould you like to parse another program? Y/n:"); @@ -91,7 +91,7 @@ namespace Assignment_1 else { // Need the logic to prep the next source stream - ck = new(); + ck = new ConsoleKeyInfo(); while (ck.Key != ConsoleKey.Y && ck.Key != ConsoleKey.N) { Console.WriteLine("\nWould you like to pipe data from source file? Y/n:"); @@ -124,7 +124,7 @@ namespace Assignment_1 public class Parser { - Dictionary> Symbols = new() + Dictionary> Symbols = new Dictionary>() { { "SPACE", new Tuple(" ", VariableFlags.Reserved | VariableFlags.NoPrint) }, { "TAB", new Tuple("\t", VariableFlags.Reserved | VariableFlags.NoPrint) }, @@ -390,7 +390,7 @@ namespace Assignment_1 int keyWidth = 21; int valueWidth = 50; int flagWidth = 9; - StringBuilder consoleOutput = new(); + StringBuilder consoleOutput = new StringBuilder(); consoleOutput.Append(string.Format("┌" + new string('─', keyWidth) + "┬" + new string('─', valueWidth) + "┬" + new string('─', flagWidth) + "┐\n")); consoleOutput.Append(string.Format("│{0}│{1}│{2}│\n", CenterString("Symbol", keyWidth), CenterString("Value", valueWidth), CenterString("Flags", flagWidth))); // Figure out how many symbols are eligible for printing @@ -462,7 +462,7 @@ namespace Assignment_1 } Action Print(Stream source, int mode = 0) { - StringBuilder outputString = new(); + StringBuilder outputString = new StringBuilder(); string expression = ValidateValue(source); if (mode == 0) { @@ -499,7 +499,7 @@ namespace Assignment_1 string key = ValidateKey(source, true); string ToReverse = Symbols[key].Item1; string[] words = ToReverse.Split(' '); - StringBuilder reversed = new(); + StringBuilder reversed = new StringBuilder(); for (int i = words.Length - 1; i >= 0; i--) { reversed.Append(words[i]); @@ -706,7 +706,7 @@ namespace Assignment_1 /// static long FindNextWord(Stream s, out string nextWord) { - StringBuilder newWord = new(); + StringBuilder newWord = new StringBuilder(); // Record our current position long start = s.Position; // Check if the character at the current pos is whitespace, if so, keep advancing until it isn't. @@ -895,7 +895,7 @@ namespace Assignment_1 static List GetStringLines(string source, int maxWidth) { - List lines = new(); + List lines = new List(); int j = 0; while (j < source.Length) {