private void WriteFixed(ColorString value, int width, TypeCode typeCode) { var len = value.String.Length; if (len == width) { Write(value); } else if (len < width) { // right align numbers string padded = typeCode >= TypeCode.SByte && typeCode <= TypeCode.Decimal ? value.String.PadLeft(width) : value.String.PadRight(width); Write(padded, value.Foreground, value.Background); } else { Write(value.String.Substring(0, width - 1), value.Foreground, value.Background); Write(_Ellipsis); } }
private void Write(ColorString cs) { Write(cs.String, cs.Foreground, cs.Background); }
private void DumpComplexEnumerable(TypeDetails details, object instance, int padding) { int?count; var items = details.GetEnumerableMemberValues(instance, ENUMERABLE_LIMIT, out count); var itemType = details.ItemDetails; int columnCount = itemType.Members.Length; var columnWidths = new int[columnCount]; int columnIndex; ColorString[] row; var allValues = new List <ColorString[]>(items.Count + 1); // get the column headings columnIndex = 0; row = new ColorString[columnCount]; foreach (var member in itemType.Members) { row[columnIndex] = new ColorString(member.Name, HEADING_FOREGROUND, HEADING_BACKGROUND); columnWidths[columnIndex] = member.Name.Length; columnIndex++; } allValues.Add(row); // get all the values foreach (var item in items) { if (item == null) { allValues.Add(null); continue; } columnIndex = 0; row = new ColorString[columnCount]; foreach (var value in item) { var cs = GetString(value); row[columnIndex] = cs; if (cs.String.Length > columnWidths[columnIndex]) { columnWidths[columnIndex] = cs.String.Length; } columnIndex++; } allValues.Add(row); } // echo WriteEnumerableLabel(details, items.Count, count, padding); padding++; int rowCount = 0; foreach (var item in allValues) { WritePadding(padding); if (item == null) { Write(_Null); } else { columnIndex = 0; foreach (var value in item) { // grab TypeCode but not for headings var typeCode = rowCount == 0 ? TypeCode.String : itemType.Members[columnIndex].TypeDetails.SimpleTypeCode; Write(_Separator); WriteFixed(value, columnWidths[columnIndex], typeCode); columnIndex++; } } WriteLine(); rowCount++; } }