public static TestType Load(IValueStream stream) { stream.EnterSequence(); var nullValue = stream.GetNull(); var booleanValue = stream.GetBoolean(); var optionalValue = Value <Option <byte> > .Loader(stream); var choice = stream.EnterChoice(); ITestChoice choiceValue = null; switch (choice) { case 0: choiceValue = FloatChoice.Load(stream); break; case 1: choiceValue = DoubleChoice.Load(stream); break; case 2: choiceValue = StringChoice.Load(stream); break; } stream.LeaveChoice(); var arrayValue = ReadOnlyArray <ushort> .Load(stream); return(new TestType(nullValue, booleanValue, optionalValue, choiceValue, arrayValue)); }
private static void ListConcise(List <string> sortedNames) { var currentDefaultCredential = GetDefaultCredential(); int maxLength = sortedNames.Max(n => n.Length); string fmtConcise = string.Format("{{0,-{0}}}", maxLength + 1); int columns = Console.WindowWidth / (maxLength + 1); int row = 0; int rows = (int)Math.Ceiling((double)sortedNames.Count / (double)columns); Regex regDefault = null; //for finding the default name in the output string. StringBuilder[] sbRows = new StringBuilder[rows]; foreach (var profileName in sortedNames) { if (sbRows[row] == null) { sbRows[row] = new StringBuilder(); } var creds = ProfileManager.GetAWSCredentials(profileName).GetCredentials(); if (creds.AccessKey == currentDefaultCredential) { regDefault = new Regex(string.Format(@"(\r|\n|^| )({0})(\r|\n|$| )", profileName)); //single out default for highlighting } sbRows[row].AppendFormat(fmtConcise, profileName); row = ++row % rows; } string s = string.Join("\r\n", Array.ConvertAll(sbRows, r => r.ToString())); //join all rows into a single string if (regDefault == null) { Console.WriteLine(s); } else { var match = regDefault.Match(s); if (match.Length == 0) { Console.WriteLine(s); } else { string deflt = match.Groups[2].Value; int pos = match.Index + match.Groups[1].Length; Console.Write(s.Substring(0, pos)); StringChoice.WriteWithHighlighting(deflt); Console.WriteLine(s.Substring(pos + deflt.Length)); } } Console.WriteLine(); }