I am trying to achieve something like this in C#:
public class GenericModel
{
public SetPropertiesFromDataRow(DataColumnCollection columns, DataRow row)
{
foreach(DataColumn column in columns)
{
this.SetProperty(column.ColumnName, row[column.ColumnName]);
}
}
}
DataTable students = ReadStudentsFromDatabase(); // This reads all the students from the database and returns a DataTable
var firstStudent = new GenericModel();
firstStudent.SetPropertiesFromDataRow(students.Columns, students.Rows[0]);
Is this possible to do in C# (since it is a static language)?
(Note that this example is somekind of psudocode.)