API Reference
This section provides a detailed reference for the public API of the ConsoleTables library.
ConsoleTable
Class
The main class for creating and managing tables.
Constructors
-
public ConsoleTable(params string[] columns)
- Creates a new table with the specified column headers.
-
public ConsoleTable(ConsoleTableOptions options)
- Creates a new table using a provided
ConsoleTableOptions
object.
- Creates a new table using a provided
Properties
-
public IList<object> Columns { get; }
- Gets the list of column headers.
-
public IList<object[]> Rows { get; }
- Gets the list of rows in the table. Each
object[]
represents a single row.
- Gets the list of rows in the table. Each
-
public ConsoleTableOptions Options { get; }
- Gets the options object associated with the table.
-
public int MaxWidth { get; set; }
- Gets or sets the maximum width of a cell before its content is wrapped. Default is
40
.
- Gets or sets the maximum width of a cell before its content is wrapped. Default is
-
public char WordBreakDelimiter { get; private set; }
- Gets the character used for word breaking when wrapping text. Default is a space character.
Methods
-
public ConsoleTable AddRow(params object[] values)
- Adds a new row to the table. The number of values must match the number of columns.
-
public ConsoleTable AddColumn(IEnumerable<string> names)
- Adds new columns to the table.
-
public ConsoleTable Configure(Action<ConsoleTableOptions> action)
- Configures the table's options using an action.
-
public ConsoleTable SetWordBreakDelimiter(char delimiter)
- Sets the delimiter for word breaking.
-
public void Write(Format format = ConsoleTables.Format.Default)
- Writes the formatted table to the output target (default is
Console.Out
).
- Writes the formatted table to the output target (default is
-
public override string ToString()
- Returns the table as a string in the
Default
format.
- Returns the table as a string in the
-
public string ToMarkDownString()
- Returns the table as a string in Markdown format.
-
public string ToMinimalString()
- Returns the table as a string in the
Minimal
format.
- Returns the table as a string in the
-
public string ToStringAlternative()
- Returns the table as a string in the
Alternative
format.
- Returns the table as a string in the
Static Factory Methods
-
public static ConsoleTable From<T>(IEnumerable<T> values)
- Creates a table from a collection of objects. Public properties of
T
are used as columns.
- Creates a table from a collection of objects. Public properties of
-
public static ConsoleTable From(DataTable dataTable)
- Creates a table from a
System.Data.DataTable
.
- Creates a table from a
-
public static ConsoleTable FromDictionary(Dictionary<string, Dictionary<string, object>> values)
- Creates a table from a nested dictionary.
-
public static ConsoleTable From(Object[][] values)
- Creates a table from a 2D object array. The first row is assumed to be the header.
ConsoleTableOptions
Class
Container for table configuration options.
Properties
-
public IEnumerable<string> Columns { get; set; }
- The column headers for the table.
-
public bool EnableCount { get; set; }
- If
true
, a "Count: X" footer is displayed. Default istrue
.
- If
-
public Alignment NumberAlignment { get; set; }
- Sets the alignment for numeric types when using
From<T>
. Default isAlignment.Left
.
- Sets the alignment for numeric types when using
-
public TextWriter OutputTo { get; set; }
- The
TextWriter
to which the table will be written. Default isConsole.Out
.
- The
Format
Enum
Specifies the rendering style for the table.
Default
: Standard style with-
and|
.MarkDown
: GitHub-Flavored Markdown table.Alternative
: Style with+
at border intersections.Minimal
: Style with no vertical borders and only a header underline.
Alignment
Enum
Specifies the text alignment within a cell.
Left
Right