Table of Contents

Class Table

Namespace
Acuit.Pinpoint.Tables
Assembly
Acuit.Pinpoint.Tables.dll

A table.

public class Table
Inheritance
Table
Inherited Members

Remarks

A table is a collection of rows, where each row is a collection of non-null string fields.

A tables can optionally contain headers, which is a collection of non-null string names that describe each column in the table.

The number of headers and the number of fields in each row do not have to match.

Tables are immutable.

Constructors

Table()

Initializes a new instance of the Table class with no headers and no rows.

public Table()

Table(IReadOnlyList<string>?, IReadOnlyList<IReadOnlyList<string>>)

Initializes a new instance of the Table class.

public Table(IReadOnlyList<string>? headers, IReadOnlyList<IReadOnlyList<string>> rows)

Parameters

headers IReadOnlyList<string>

The header row, or null if there is no header row.

rows IReadOnlyList<IReadOnlyList<string>>

The list of rows.

Exceptions

ArgumentNullException

rows is null.

Properties

ColumnCount

Gets the column count.

public int ColumnCount { get; }

Property Value

int

Remarks

Each row (and the header row) in the table can have different field counts. This value will reflect the row (or header row) with the most fields. Some rows (or the header row) could have fewer fields than this value. This will return 0 if there are no headers and no rows.

Headers

Gets the header row, or null if there is no header row.

public IReadOnlyList<string>? Headers { get; }

Property Value

IReadOnlyList<string>

LooseHeaderStringComparer

Gets a string comparer that can be used to loosely compare table headers, disregarding case (per the invariant culture), white-space characters, and underscores.

public static StringComparer LooseHeaderStringComparer { get; }

Property Value

StringComparer

Remarks

This is effectively the same as OrdinalIgnoreCase, with the addition of ignoring white-space characters and underscores.

Rows

Gets the list of rows.

public IReadOnlyList<IReadOnlyList<string>> Rows { get; }

Property Value

IReadOnlyList<IReadOnlyList<string>>

Methods

EnumerateHeaderAndRows()

Enumerates all rows in the table, including the header row if one exists.

public IEnumerable<IReadOnlyList<string>> EnumerateHeaderAndRows()

Returns

IEnumerable<IReadOnlyList<string>>

An enumerable collection of rows, starting with the header row if one exists.

FindHeaderIndex(string, StringComparer)

Finds the index of a column for a given header.

public int FindHeaderIndex(string header, StringComparer comparer)

Parameters

header string

The column header.

comparer StringComparer

The string comparer to use. Consider using LooseHeaderStringComparer for this.

Returns

int

The index of the matching column, or -1 if none matched.

Exceptions

ArgumentNullException

header is null.

ArgumentNullException

comparer is null.

InvalidOperationException

The table does not contain a header row.

InvalidOperationException

Multiple column headers in the table match.

IsEquivalentTo(Table)

Compares this table content to another.

public bool IsEquivalentTo(Table other)

Parameters

other Table

The other table to compare.

Returns

bool

true if the table content is identical; otherwise false.

Exceptions

ArgumentNullException

other is null.

RemoveEmptyOrWhiteSpaceRowsAndColumns()

Returns a new table with all empty or white-space rows and columns removed.

public Table RemoveEmptyOrWhiteSpaceRowsAndColumns()

Returns

Table

A new table with all empty or white-space rows and columns removed.

Remarks

For a row to be empty or white-space, every field in the row must be empty or only contain white-space characters. For a column to be empty or white-space, the field in that column in the header and in all rows must be empty or only contain white-space characters.

RemoveEmptyRowsAndColumns()

Returns a new table with all empty rows and columns removed.

public Table RemoveEmptyRowsAndColumns()

Returns

Table

A new table with all empty rows and columns removed.

Remarks

For a row to be empty, every field in the row must be empty. For a column to be empty, the field in that column in the header and in all rows must be empty.

TryGetCellValue(IReadOnlyList<string>, string?, StringComparer, GetCellOptions, out string?)

Tries to get a cell value from a row in the table column with a given header.

public bool TryGetCellValue(IReadOnlyList<string> row, string? header, StringComparer comparer, GetCellOptions cellOptions, out string? value)

Parameters

row IReadOnlyList<string>

The row from the table.

header string

The optional column header. If this is null or empty, no column will be found.

comparer StringComparer

The string comparer to use. Consider using LooseHeaderStringComparer for this.

cellOptions GetCellOptions

Options that indicate how to interpret the cell value.

value string

On return, the cell value if the column and cell value were found; otherwise, null.

Returns

bool

true if the column and cell value were found; otherwise, false.

Remarks

The column and cell value are considered "found" when all of the following are true:

  • A table column for header is found.
  • row is large enough to have an element at the table column index, and the element is not null.
  • After trimming white space if cellOptions specifies TrimWhiteSpace, the value is not empty, unless cellOptions specifies AllowEmpty.

This method does not validate that header is specified or the table column exists. Any such validation should occur separately, before table row content is being read, as this method cannot be relied upon to perform this validation since it would never be called when a table does not contain any rows.

row is not required to be an element of Rows.

Exceptions

ArgumentNullException

row is null.

ArgumentNullException

comparer is null.

InvalidOperationException

The table does not contain a header row.

TryGetCellValue(IReadOnlyList<string>, string?, StringComparer, out string?)

Tries to get a cell value from a row in the table column with a given header.

public bool TryGetCellValue(IReadOnlyList<string> row, string? header, StringComparer comparer, out string? value)

Parameters

row IReadOnlyList<string>

The row from the table.

header string

The optional column header. If this is null or empty, no column will be found.

comparer StringComparer

The string comparer to use. Consider using LooseHeaderStringComparer for this.

value string

On return, the cell value if the column and cell value were found; otherwise, null.

Returns

bool

true if the column and cell value were found; otherwise, false.

Remarks

This is equivalent to TryGetCellValue(IReadOnlyList<string>, string?, StringComparer, GetCellOptions, out string?) with None; see the remarks for that overload for more information.

Exceptions

ArgumentNullException

row is null.

ArgumentNullException

comparer is null.

InvalidOperationException

The table does not contain a header row.