37 lines
940 B
C#
37 lines
940 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace Maticsoft.DBUtility
|
|
{
|
|
public class Mapper
|
|
{
|
|
public static T CreateItem<T>(DataRow row)
|
|
{
|
|
T obj = default(T);
|
|
if (row != null)
|
|
{
|
|
obj = Activator.CreateInstance<T>();
|
|
|
|
foreach (DataColumn column in row.Table.Columns)
|
|
{
|
|
PropertyInfo prop = obj.GetType().GetProperty(column.ColumnName);
|
|
try
|
|
{
|
|
object value = row[column.ColumnName];
|
|
prop.SetValue(obj, value, null);
|
|
}
|
|
catch
|
|
{ //You can log something here
|
|
//throw;
|
|
}
|
|
}
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
}
|
|
}
|