in CommandLine/XblConfig/ObjectPrinter.cs [59:110]
public static string Print(IEnumerable list, IEnumerable<PropertyInfo> properties)
{
if (properties == null)
{
return string.Empty;
}
StringBuilder formatSB = new StringBuilder();
StringBuilder headerFormatSB = new StringBuilder();
int index = 0;
IDictionary<string, string> propertyNames = GetPropertyNames(properties);
foreach (PropertyInfo property in properties)
{
int maxLength = propertyNames[property.Name].Length;
foreach (object item in list)
{
int len = item.GetType().GetProperty(property.Name).GetValue(item).ToString().Length;
if (len > maxLength)
{
maxLength = len;
}
}
headerFormatSB.Append($"{{{index}, -{maxLength + VirtualTerminal.Underline.Length + VirtualTerminal.Reset.Length}}} ");
formatSB.Append($"{{{index++}, -{maxLength}}} ");
}
string format = formatSB.ToString().Trim();
string headerFormat = headerFormatSB.ToString().Trim();
StringBuilder sb = new StringBuilder();
string[] namesOld = propertyNames.Select(c => $"{c.Value}").ToArray();
string[] names = propertyNames.Select(c => $"{VirtualTerminal.Underline}{c.Value}{VirtualTerminal.Reset}").ToArray();
sb.AppendFormat(headerFormat, names);
sb.AppendLine();
foreach (object item in list)
{
List<object> items = new List<object>();
foreach (PropertyInfo property in properties)
{
items.Add(property.GetValue(item));
}
sb.AppendFormat(format, items.ToArray());
sb.AppendLine();
}
return sb.ToString();
}