Table of Contents

Class Table

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

A table.

public class Table
Inheritance
Table
Inherited Members

Constructors

Table()

Initializes a new instance of the Table class.

public Table()

Table(TextReader, bool)

Initializes a new instance of the Table class.

public Table(TextReader reader, bool hasHeaderRow)

Parameters

reader TextReader

The text reader from which to read the CSV table data.

hasHeaderRow bool

Whether the first row in the table is a header row.

Remarks

Blank lines are ignored, but lines containing only whitespace will be parsed as rows with a single field containing the whitespace.

Exceptions

ArgumentNullException

reader is null.

Exception

An error occurred while parsing the data.

Table(string, bool)

Initializes a new instance of the Table class.

public Table(string csv, bool hasHeaderRow)

Parameters

csv string

The CSV text from which to initialize the table data.

hasHeaderRow bool

Whether the first row in the table is a header row.

Remarks

Blank lines are ignored, but lines containing only whitespace will be parsed as rows with a single field containing the whitespace.

Exceptions

ArgumentNullException

csv is null.

Exception

An error occurred while parsing the data.

Properties

ColumnCount

Gets the column count.

public int ColumnCount { get; }

Property Value

int

Remarks

Each row (and 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 header row) could have fewer fields than this value.

Headers

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

public string[] Headers { get; set; }

Property Value

string[]

Rows

Gets the list of rows.

public IList<string[]> Rows { get; }

Property Value

IList<string[]>

Methods

EnumerateHeaderAndRows()

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

public IEnumerable<string[]> EnumerateHeaderAndRows()

Returns

IEnumerable<string[]>

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

FindHeaderIndex(string)

Finds the index of a column for a given header.

public int FindHeaderIndex(string header)

Parameters

header string

The column header.

Returns

int

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

Remarks

Column headers are loosely matched, disregarding case, white space, and underscores.

Exceptions

InvalidOperationException

The table does not contain a header row.

InvalidOperationException

Multiple column headers in the table match.

Import(Stream, string, bool)

Imports a table from a file stream.

public static Table Import(Stream fileStream, string fileName, bool hasHeaderRow)

Parameters

fileStream Stream

The file stream from which to read the table data.

fileName string

The file name, which is only used to look at the file extension to determine the type of source file.

hasHeaderRow bool

Whether the first row in the table is a header row.

Returns

Table

A Table containing the imported data.

Exceptions

ArgumentNullException

fileStream is null.

ArgumentNullException

fileName is null.

InvalidOperationException

The file type is not supported.

Exception

Some other error occurred while reading or parsing the data. The possible list of exceptions depends on which importer is being used.

Import(string, bool)

Imports a table from a file.

public static Table Import(string path, bool hasHeaderRow)

Parameters

path string

A relative or absolute path for the file from which to read the table data.

hasHeaderRow bool

Whether the first row in the table is a header row.

Returns

Table

A Table containing the imported data.

Exceptions

ArgumentNullException

path is null.

InvalidOperationException

The file type is not supported.

Exception

Some other error occurred while reading or parsing the data. The possible list of exceptions depends on which importer is being used.

IsColumnEmpty(int)

Gets whether a column is empty.

public bool IsColumnEmpty(int columnIndex)

Parameters

columnIndex int

The column index.

Returns

bool

true if every field in the column (including the header) is empty.

Exceptions

ArgumentOutOfRangeException

columnIndex is less than zero or greater than or equal to ColumnCount.

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.

IsFieldEmpty(string)

Gets whether a field is empty.

public static bool IsFieldEmpty(string field)

Parameters

field string

A field value.

Returns

bool

true if the field value is null, empty, or only contains white space.

IsRowEmpty(string[])

Gets whether a row is empty.

public static bool IsRowEmpty(string[] row)

Parameters

row string[]

A row.

Returns

bool

true if every field in the row is empty.

Exceptions

ArgumentNullException

row is null.

RemoveColumn(int)

Removes a column from the table.

public void RemoveColumn(int columnIndex)

Parameters

columnIndex int

The column index.

Exceptions

ArgumentOutOfRangeException

columnIndex is less than zero or greater than or equal to ColumnCount.

RemoveEmptyColumns()

Removes all empty columns from the table.

public void RemoveEmptyColumns()

Remarks

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

RemoveEmptyRows()

Removes all empty rows from the table.

public void RemoveEmptyRows()

Remarks

For a row to be empty, every field in the row must be empty. The header, if it exists, will not be changed, even if it is empty.

ToCsv()

Produces the table data as a CSV-formatted string.

public string ToCsv()

Returns

string

The table data as a CSV-formatted string.

TruncateColumns(int)

Truncates columns from the table.

public void TruncateColumns(int columnCount)

Parameters

columnCount int

The new column count.

Remarks

If columnCount is greather than or equal to ColumnCount, the table will not be changed.

Exceptions

ArgumentOutOfRangeException

columnCount is less than zero.