类
public static class ToModel
{
public static TModel DataToModel<TModel>(this DataRow dr)
{
Type type = typeof(TModel);
TModel md = (TModel)Activator.CreateInstance(type);
foreach(var prop in type.GetProperties())
{
prop.SetValue(md,dr[prop.Name]);
}
return md;
}
}
{message type="success"}使用:dr.DataToModel<userinfo>(){/message}
评论 (0)