I have some function like
private static UserInfo FillUserInfoFromDataRow(DataRow dr)
{
UserInfo user = new UserInfo();
user.UserID = (int) dr["UserID"];
user.UserName = (int) dr["UserName"];
user.ProjectID = (int) dr["ProjectID"];
user.ClassID = (int) dr["ClassID"];
..............
return user;
}
I’d like to write some generic function like
private static T FillEntityInfoFromDataRow(DataRow dr), that will treat analogous types ProjectInfo, JobInfo, etc.
I can get all columns names of the DataRow parameter, but I don’t know how to get all the appropriate fields of the generic T type and how to do appropriate casting.
Is it some way to do this job?
Thanks!
Ilan.
Its better to make use of reflection there are no of example avaible on google to do this this.
Check the below example
Check the full blog post : http://kasey-jo.blogspot.com/2009/04/using-reflection-to-fill-business-layer.html