Show / Hide Table of Contents

Class DataTableExtensions

Data table extension methods

Inheritance
object
DataTableExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: PayrollEngine.Client.Scripting.Report
Assembly: PayrollEngine.Client.Scripting.dll
Syntax
public static class DataTableExtensions

Methods

View Source

AddColumn(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
View Source

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
View Source

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

View Source

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
View Source

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
View Source

Any(DataTable)

Test for rows

Declaration
public static bool Any(this DataTable table)
Parameters
Type Name Description
DataTable table
Returns
Type Description
bool
View Source

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
View Source

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

View Source

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

View Source

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
View Source

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

View Source

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
View Source

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
View Source

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

View Source

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
View Source

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
View Source

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

View Source

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
View Source

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
View Source

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

View Source

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
View Source

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

View Source

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
View Source

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

View Source

RemovePrimaryKey(DataTable)

Remove the table primary key

Declaration
public static void RemovePrimaryKey(this DataTable table)
Parameters
Type Name Description
DataTable table
View Source

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

View Source

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

View Source

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

View Source

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>
View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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
  • View Source
☀
☾
Back to top Generated by DocFX