/// <summary> /// Creates a new DataRow and adds it /// to the source DataTable for the supplied /// object. /// </summary> /// <typeparam name="T">Typed DataRow</typeparam> /// <param name="source">Object to add to the DataTable.</param> /// <param name="table">DataTable to add the row to.</param> /// <returns></returns> public static T AsDataRow <T>( this object source, DataTable table) where T : DataRow { source.AssertParameterNotNull( "Cannot convert a null source to a DataRow.", "source"); table.AssertParameterNotNull( "Cannot add a DataRow to a null DataTable.", "table"); T result = null; List <DataColumn> columns = MakeDataColumns(source); if (columns.IsNotEmpty()) { table.AddColumnsToDataTable(columns); result = (T)table.NewRow(); result.PopulateDataRow(source, columns); table.Rows.Add(result); } return(result); }