| | | 1 | | |
| | | 2 | | namespace Kestrun.Logging.Utils.Console.Extensions; |
| | | 3 | | |
| | | 4 | | /// <summary> |
| | | 5 | | /// Provides extension methods for the <see cref="Table"/> class. |
| | | 6 | | /// </summary> |
| | | 7 | | public static class TableExtensions |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Adds one row with two cells into <see cref="Table"/> only if <paramref name="propertyValue"/> is not null or emp |
| | | 11 | | /// </summary> |
| | | 12 | | /// <param name="table"></param> |
| | | 13 | | /// <param name="propertyName"></param> |
| | | 14 | | /// <param name="propertyValue"></param> |
| | | 15 | | public static void AddPropertyRow(this Table table, string propertyName, object propertyValue) |
| | | 16 | | { |
| | 25 | 17 | | if (propertyValue == null || (propertyValue is string propertyValueString && string.IsNullOrEmpty(propertyValueS |
| | | 18 | | { |
| | 12 | 19 | | return; |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | // Avoid calling ToString() on non-string values here; Table and Cell will defer formatting. |
| | | 23 | | // Clamp extremely long strings to keep rendering safe and bounded. |
| | 13 | 24 | | if (propertyValue is string s) |
| | | 25 | | { |
| | | 26 | | const int maxLen = 8_192; // safety cap |
| | 5 | 27 | | var safe = s.Length > maxLen ? s[..maxLen] + "…" : s; |
| | 5 | 28 | | table.AddRow(propertyName, safe); |
| | | 29 | | } |
| | | 30 | | else |
| | | 31 | | { |
| | 8 | 32 | | table.AddRow(propertyName, propertyValue); |
| | | 33 | | } |
| | 8 | 34 | | } |
| | | 35 | | } |