Class DataTableExtensions
Data table extension methods
Inherited Members
Namespace: PayrollEngine.Client.Scripting.Report
Assembly: PayrollEngine.Client.Scripting.dll
Syntax
public static class DataTableExtensions
Methods
View SourceAddColumn(DataTable, string, Type, string)
Add table column
Declaration
public static DataColumn AddColumn(this DataTable table, string columnName, Type type, string expression = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| Type | type | The column type |
| string | expression | The compute expression |
Returns
| Type | Description |
|---|---|
| DataColumn |
AddColumn<T>(DataTable, string, string)
Add table column
Declaration
public static DataColumn AddColumn<T>(this DataTable table, string columnName, string expression = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| string | expression | The compute expression |
Returns
| Type | Description |
|---|---|
| DataColumn |
Type Parameters
| Name | Description |
|---|---|
| T |
AddLocalizationColumn(DataTable, string, string, string)
Add localization column
Declaration
public static DataColumn AddLocalizationColumn(this DataTable table, string culture, string columnName, string localizationsColumnName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | culture | Localization culture |
| string | columnName | Name of the source column |
| string | localizationsColumnName | Name of the localizations column (default: columnNameLocalizations) |
Returns
| Type | Description |
|---|---|
| DataColumn |
Remarks
Requires
AddRelationColumn(DataTable, string, int)
Add table relation integer column with initial value
Declaration
public static DataColumn AddRelationColumn(this DataTable table, string columnName, int relationId)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| int | relationId | Value to set to all rows |
Returns
| Type | Description |
|---|---|
| DataColumn |
AddRelationColumn<T>(DataTable, string, object)
Add table relation column with initial value
Declaration
public static DataColumn AddRelationColumn<T>(this DataTable table, string columnName, object relationValue)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| object | relationValue | Value to set to all rows |
Returns
| Type | Description |
|---|---|
| DataColumn |
Type Parameters
| Name | Description |
|---|---|
| T |
Any(DataTable)
Test for rows
Declaration
public static bool Any(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| bool |
Any(DataTable, Func<DataRow, bool>)
Test for rows by function
Declaration
public static bool Any(this DataTable table, Func<DataRow, bool> anyFunc)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| Func<DataRow, bool> | anyFunc | Any functions |
Returns
| Type | Description |
|---|---|
| bool |
AsDictionary(DataTable)
Get data table as dictionary
Declaration
public static List<Dictionary<string, object>> AsDictionary(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| List<Dictionary<string, object>> | List of row dictionaries |
AsSingleRow(DataTable)
Get as single row table
Declaration
public static DataRow AsSingleRow(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| DataRow | The single row, null on table with multiple rows |
ContainsColumn(DataTable, string)
Test for table column
Declaration
public static bool ContainsColumn(this DataTable table, string columnName)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
Returns
| Type | Description |
|---|---|
| bool |
DeleteRows(DataTable, string)
Delete table rows by filter
Declaration
public static int DeleteRows(this DataTable table, string filterExpression)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | filterExpression | The filter matching the rows to delete |
Returns
| Type | Description |
|---|---|
| int | The deleted row count |
EnsureColumn(DataTable, string, Type, string)
Ensure table column
Declaration
public static DataColumn EnsureColumn(this DataTable table, string columnName, Type type, string expression = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| Type | type | The column type |
| string | expression | The compute expression |
Returns
| Type | Description |
|---|---|
| DataColumn |
EnsureColumn<T>(DataTable, string, string)
Ensure table column
Declaration
public static DataColumn EnsureColumn<T>(this DataTable table, string columnName, string expression = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
| string | expression | The compute expression |
Returns
| Type | Description |
|---|---|
| DataColumn |
Type Parameters
| Name | Description |
|---|---|
| T |
EnsureColumns(DataTable, DataColumnCollection)
Ensure table column
Declaration
public static void EnsureColumns(this DataTable table, DataColumnCollection columns)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| DataColumnCollection | columns | The columns to ensure |
EnsureColumns<T>(DataTable, IEnumerable<string>)
Ensure table columns
Declaration
public static void EnsureColumns<T>(this DataTable table, IEnumerable<string> columns)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| IEnumerable<string> | columns | The columns to ensure |
Type Parameters
| Name | Description |
|---|---|
| T |
FindFirstRow<T>(DataTable, string, T)
Find row by value search
Declaration
public static DataRow FindFirstRow<T>(this DataTable table, string column, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | column | The search column name |
| T | value | The search key |
Returns
| Type | Description |
|---|---|
| DataRow | The matching data ro or null |
Type Parameters
| Name | Description |
|---|---|
| T |
GetDictionary(DataTable, string, string, string)
Get data table rows JSON value as dictionary
Declaration
public static Dictionary<string, string> GetDictionary(this DataTable table, string column, string keyField, string valueField)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | column | The column name |
| string | keyField | The json object key field |
| string | valueField | The json object value field |
Returns
| Type | Description |
|---|---|
| Dictionary<string, string> | The data table rows value |
GetRowValue<T>(DataTable, string, object, string, T)
Get row table value by value search
Declaration
public static T GetRowValue<T>(this DataTable table, string keyColumn, object keyValue, string valueColumn, T defaultValue = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | keyColumn | The search column name |
| object | keyValue | The search key |
| string | valueColumn | The value column name |
| T | defaultValue | The default value |
Returns
| Type | Description |
|---|---|
| T | The data row value |
Type Parameters
| Name | Description |
|---|---|
| T |
GetValues<T>(DataTable, string, T)
Get data table rows value
Declaration
public static List<T> GetValues<T>(this DataTable table, string column, T defaultValue = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | column | The column name |
| T | defaultValue | The default value |
Returns
| Type | Description |
|---|---|
| List<T> | The data table rows value |
Type Parameters
| Name | Description |
|---|---|
| T |
HasRows(DataTable)
Test for any table rows
Declaration
public static bool HasRows(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| bool | True if rows are present |
InsertColumn<T>(DataTable, int, string, string)
Insert table column at certain list position
Declaration
public static DataColumn InsertColumn<T>(this DataTable table, int index, string columnName, string expression = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| int | index | The column list position |
| string | columnName | Name of the column |
| string | expression | The compute expression |
Returns
| Type | Description |
|---|---|
| DataColumn |
Type Parameters
| Name | Description |
|---|---|
| T |
IsSingleRow(DataTable)
Test for single row table
Declaration
public static bool IsSingleRow(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| bool | True for a single row collection |
Json(DataTable, JsonNamingPolicy, bool)
Get data table as json
Declaration
public static string Json(this DataTable table, JsonNamingPolicy namingPolicy = null, bool ignoreNull = true)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| JsonNamingPolicy | namingPolicy | Naming policy (default: camel case) |
| bool | ignoreNull | Ignore null values (default: true) |
Returns
| Type | Description |
|---|---|
| string |
RemoveColumn(DataTable, string)
Remove table column
Declaration
public static void RemoveColumn(this DataTable table, string columnName)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
RemovePrimaryKey(DataTable)
Remove the table primary key
Declaration
public static void RemovePrimaryKey(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
RenameColumn(DataTable, string, string)
Rename table column
Declaration
public static string RenameColumn(this DataTable table, string oldColumnName, string newColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | oldColumnName | Existing name of the column |
| string | newColumnName | Existing name of the column |
Returns
| Type | Description |
|---|---|
| string | The column name |
Rows(DataTable)
Get table rows
Declaration
public static EnumerableRowCollection Rows(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| EnumerableRowCollection | A row collection |
SelectRows(DataTable, Func<DataRow, bool>)
Selects rows by function
Declaration
public static List<DataRow> SelectRows(this DataTable table, Func<DataRow, bool> selectFunc)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| Func<DataRow, bool> | selectFunc | Select functions |
Returns
| Type | Description |
|---|---|
| List<DataRow> | The selected data rows |
SelectRows(DataTable, string)
Select table rows by filter
Declaration
public static IEnumerable<DataRow> SelectRows(this DataTable table, string filterExpression)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | filterExpression | The filter matching the rows to delete |
Returns
| Type | Description |
|---|---|
| IEnumerable<DataRow> |
SetPrimaryKey(DataTable, string)
Set the table primary key column
Declaration
public static void SetPrimaryKey(this DataTable table, string columnName)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | columnName | Name of the column |
SingleRow(DataTable)
Get single row table
Declaration
public static DataRow SingleRow(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| DataRow | The single row |
SingleRowId(DataTable)
Get single row id
Declaration
public static int SingleRowId(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| int | The data row id |
SingleRowIdentifier(DataTable)
Get single row identifier
Declaration
public static string SingleRowIdentifier(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| string | The data row identifier |
SingleRowName(DataTable)
Get single row name
Declaration
public static string SingleRowName(this DataTable table)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table |
Returns
| Type | Description |
|---|---|
| string | The data row name |
SingleRowValue<T>(DataTable, string, T)
Get single row table value
Declaration
public static T SingleRowValue<T>(this DataTable table, string column, T defaultValue = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | |
| string | column | The column name |
| T | defaultValue | The default value |
Returns
| Type | Description |
|---|---|
| T | The data row value |
Type Parameters
| Name | Description |
|---|---|
| T |