Class Table
A very basic data table storing columns and rows of string information controlled by a simple schema. Source data can be loaded from a CSV-like file with the following format:
- Dash starts a comment schema: id,*name (defines two columns, first called 'id' and second called 'name', * means this is the primary key) 0, Apples (0, Apples populates the two columns defined by schema, with an 'id' of "0" and 'name' of "Apples") 1, Oranges (and so on) Schema must be defined before first data row. Column names in schema must all be unique, at least one must be the key. Column values are always stored as strings. Key column value must be unique in every row. Can use spaces in values, but not commas (separating character only). Lookups are done by keys or by indices.
Namespace: DaggerfallWorkshop.Utility
Assembly: Assembly-CSharp.dll
Syntax
public class Table
Constructors
| Improve this Doc View SourceTable()
Default constructor.
Declaration
public Table()
Table(String)
Load constructor.
Declaration
public Table(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | Text of data file. |
Table(String[])
Load constructor.
Declaration
public Table(string[] lines)
Parameters
Type | Name | Description |
---|---|---|
String[] | lines | String array of lines in data file. |
Properties
| Improve this Doc View SourceColumnCount
Declaration
public int ColumnCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
RowCount
Declaration
public int RowCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceAddIntoTable(String[])
Adds extra rows to a data table from an array lines.
Declaration
public void AddIntoTable(string[] lines)
Parameters
Type | Name | Description |
---|---|---|
String[] | lines |
GetColumnIndex(String)
Gets column index by name.
Declaration
public int GetColumnIndex(string columnName)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | Column name. |
Returns
Type | Description |
---|---|
Int32 | Column index. |
GetColumnName(Int32)
Gets column name by index.
Declaration
public string GetColumnName(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Index of column. |
Returns
Type | Description |
---|---|
String | Name of column, or empty string. |
GetInt(String, String)
Try to get value as int.
Declaration
public int GetInt(string columnName, string key)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | |
String | key |
Returns
Type | Description |
---|---|
Int32 |
GetKeyForValue(String, String)
Declaration
public string GetKeyForValue(string columnName, string value)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | |
String | value |
Returns
Type | Description |
---|---|
String |
GetRow(Int32)
Gets a row array by index.
Declaration
public string[] GetRow(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Index of row. |
Returns
Type | Description |
---|---|
String[] | String array for row, or empty array if row not found. |
GetRow(String)
Gets a row array by key value.
Declaration
public string[] GetRow(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | Key value. |
Returns
Type | Description |
---|---|
String[] | String array for row, or empty array if row not found. |
GetRowIndex(String)
Gets index of row by key value.
Declaration
public int GetRowIndex(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | Key value. |
Returns
Type | Description |
---|---|
Int32 | Index of row, or -1 if not found. |
GetValue(String, Int32)
Gets specified value from column.
Declaration
public string GetValue(string columnName, int index)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | Column name. |
Int32 | index | Index of row. |
Returns
Type | Description |
---|---|
String | Value as string. |
GetValue(String, String)
Gets specified value from column.
Declaration
public string GetValue(string columnName, string key)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | Column name. |
String | key | Key value. |
Returns
Type | Description |
---|---|
String | Value as string. |
HasColumn(String)
Checks if column name exists in table.
Declaration
public bool HasColumn(string columnName)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | Column name. |
Returns
Type | Description |
---|---|
Boolean | True if column exists. |
HasValue(String)
Checks if a key value is present in table.
Declaration
public bool HasValue(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | Key value. |
Returns
Type | Description |
---|---|
Boolean | True if key value present. |
SetRow(String[])
Sets row data back to table. Key value must not be changed as this is used to set back correct row. Any other value can be changed as needed.
Declaration
public bool SetRow(string[] row)
Parameters
Type | Name | Description |
---|---|---|
String[] | row | Row array. |
Returns
Type | Description |
---|---|
Boolean | True if row set. |
SetValue(String, String, String)
Sets specified value in column.
Declaration
public void SetValue(string columnName, string key, string value)
Parameters
Type | Name | Description |
---|---|---|
String | columnName | Column name. |
String | key | Key value. |
String | value | Value to set. |