AddColumnsFromInterface Method
The AddColumnsFromInterface method adds columns to a data table by reflecting over a POCO interface type.
It collects the specified interface and its entire inheritance chain, then adds a column for each public instance property.
For each interface property, the method determines:
Columns are added using DataTableExtensions.AddColumn, so existing rows in the table are extended with the new columns.
/// <summary>
/// Adds columns from interface with inheritance chain
/// </summary>
/// <param name="dataTable">Data table</param>
/// <param name="interfaceType">Interface type</param>
/// <exception cref="ArgumentException">Exception is thrown if specified type is not an interface</exception>
public static void AddColumnsFromInterface(this IDataTable? dataTable, Type interfaceType)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns immediately.interfaceType.IsInterface is true. Otherwise throws ArgumentException.
interfaceType and all inherited interfaces recursively.
dataTable.AddColumn(columnName, dataTypeName, isNullable).
Primary-key and foreign-key conventions (if any) are applied by AddColumn.
Assume there is an interface that defines the schema of an EmploymentType entity:
/// <summary>
/// Defines employment type functionality
/// </summary>
internal interface IEmploymentType
{
int Id { get; set; }
string Code { get; set; }
string? Description { get; set; }
}
You can create a table and add columns from the interface:
// 1. Create an empty data set
IDataSet dataSet = DataSetFactory.CreateDataSet();
// 2. Add an empty table
IDataTable employmentTypeDataTable = dataSet.AddNewTable("EmploymentType");
// 3. Add columns from the POCO interface
employmentTypeDataTable.AddColumnsFromInterface(typeof(IEmploymentType));
AddColumn. If the table already contains a column with the same name,
AddColumn will throw a KeyDuplicationException.
AddColumn extends existing rows, calling AddColumnsFromInterface on a table with many rows
may have a performance impact.
Table of Content POCO DataSet DataTable Extensions Group DataTable Members
Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the
Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate
credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness
or suitability of the information and are not responsible for any damages
resulting from its use.